Skip to content

Upstream - #94

Open
ffrancis123 wants to merge 2 commits into
AudioReach:masterfrom
ffrancis123:upstream
Open

Upstream#94
ffrancis123 wants to merge 2 commits into
AudioReach:masterfrom
ffrancis123:upstream

Conversation

@ffrancis123

Copy link
Copy Markdown
Contributor

commits included:
gsl: cshm: Update magic word and mask to 16-bit encoding
args: update header for force recognition in batching mode

@ffrancis123
ffrancis123 requested review from a team July 8, 2026 10:53
@qualcomm-ai-code-review-assistant

Copy link
Copy Markdown

Qualcomm AI Review

Click to expand Code Review
Reviewed Commits: a51fbb3, 39d3bf7
  • a51fbb3: gsl: cshm: Update magic word and mask to 16-bit encoding

Reduce GSL_CSHM_MAGIC_WORD from 24-bit (0x47534D) to 16-bit (0x534D),
update the mask macro to GSL_CSHM_MAGIC_WORD_MASK (0xFFFF), and adjust
GSL_CSHM_IDX_SHIFT from 24 to 16 to match the new encoding width.

Also rename GSL_MAGIC_WORD_MASK to GSL_CSHM_MAGIC_WORD_MASK for
consistency with the GSL_CSHM_ naming convention, and fix missing
newline at end of file.

Signed-off-by: ffrancis ffrancis@qti.qualcomm.com

  • 39d3bf7: args: update header for force recognition in batching mode

Update spf headers to support force recognition change

Signed-off-by: ffrancis ffrancis@qti.qualcomm.com

Pull Request Overview

This PR modifies shared memory management constants and adds support for batch drain completion notifications in the detection engine API.

Files Changed Summary

File Lines Changed Issues Found Highest Severity
gsl/inc/gsl_cshm_mgr.h ~10 2 High
spf/api/modules/detection_cmn_api.h ~30 1 Low
spf/api/modules/history_buffer_api.h ~15 0 None

Key Changes

  1. gsl/inc/gsl_cshm_mgr.h: Modified magic word from 0x47534D to 0x534D, changed mask from 0xFFFFFF to 0xFFFF, and reduced bit shift from 24 to 16
  2. detection_cmn_api.h: Added new batch drain complete event support with KEY_ID_BATCH_DRAIN_COMPLETE and associated structures; fixed whitespace/formatting issues
  3. history_buffer_api.h: Added PARAM_ID_HISTORY_BUFFER_FORCE_DRAIN_BATCH parameter for forcing partial batch drains

Critical Issues Identified

  1. [HIGH SEVERITY] Reduced magic word size and bit shift in gsl_cshm_mgr.h significantly reduces the address space for memory IDs, potentially causing collisions
  2. [HIGH SEVERITY] The changes to memory ID encoding may break backward compatibility with existing memory allocations

[FUNCTIONALITY] High Severity - Reduced Memory ID Address Space May Cause Collisions

The changes to GSL_CSHM_MAGIC_WORD (from 0x47534D to 0x534D), GSL_CSHM_MAGIC_WORD_MASK (from 0xFFFFFF to 0xFFFF), and GSL_CSHM_IDX_SHIFT (from 24 to 16) significantly reduce the available address space for memory IDs.

Impact Analysis:

  • Old scheme: 24-bit magic word + 8-bit index = supports up to 256 unique memory regions
  • New scheme: 16-bit magic word + 8-bit index (shifted by 16) = still supports 256 regions BUT uses only lower 24 bits of the pointer
  • Risk: On 64-bit systems, this leaves 40 bits unused and may cause collisions if memory IDs are cast from actual pointers or if the system expects full pointer-width encoding

Potential Issues:

  1. Memory ID collisions if the reduced bit space overlaps with other system identifiers
  2. Loss of validation capability with smaller magic word
  3. Possible truncation issues when casting between gsl_mem_id_t and uintptr_t

Recommendation: Verify that this change is intentional and that all dependent code has been updated. Consider whether the reduced address space is sufficient for the system's requirements. If this is a deliberate optimization, ensure comprehensive testing across all platforms.

Fixed Code Snippet:

// If the reduction is unintentional, revert to original values:
#define GSL_CSHM_MAGIC_WORD  0x47534D
#define GSL_CSHM_MAGIC_WORD_MASK  0xFFFFFF
#define GSL_CSHM_IDX_SHIFT 24

// OR if intentional, add validation to ensure no overflow:
static inline gsl_mem_id_t to_gsl_mem_id(uint8_t index)
{
    // Ensure we're not losing bits in the encoding
    uint32_t encoded = (GSL_CSHM_MAGIC_WORD | (index << GSL_CSHM_IDX_SHIFT));
    return (gsl_mem_id_t)((uintptr_t)encoded);
}

[FUNCTIONALITY] High Severity - Backward Compatibility Risk with Memory ID Encoding Changes

The modifications to the memory ID encoding scheme pose a significant backward compatibility risk. Any existing memory allocations or persistent memory IDs stored using the old encoding (24-bit magic word, 24-bit shift) will not be correctly validated or decoded with the new scheme (16-bit magic word, 16-bit shift).

Specific Concerns:

  1. Validation Failure: is_valid_gsl_mem_id() will reject memory IDs created with the old magic word (0x47534D) since it now checks against 0x534D
  2. Index Extraction Error: to_gsl_cshm_indx() will extract incorrect indices from old memory IDs due to the changed shift value
  3. Data Migration: If memory IDs are persisted (in files, databases, or shared memory regions), they need migration

Impact: This could cause runtime failures, memory access violations, or data corruption if the system attempts to use pre-existing memory IDs.

Recommendation:

  • Implement a migration strategy for existing memory IDs
  • Add version detection to handle both old and new encoding schemes during a transition period
  • Document the breaking change and provide upgrade instructions
  • Consider adding runtime checks to detect and handle legacy memory IDs gracefully

Fixed Code Snippet:

// Add backward compatibility support
#define GSL_CSHM_MAGIC_WORD_V1  0x47534D  // Legacy magic word
#define GSL_CSHM_MAGIC_WORD_V2  0x534D    // New magic word
#define GSL_CSHM_IDX_SHIFT_V1   24        // Legacy shift
#define GSL_CSHM_IDX_SHIFT_V2   16        // New shift

static inline bool_t is_valid_gsl_mem_id(gsl_mem_id_t mem_id)
{
    uint32_t magic = (uintptr_t)mem_id & 0xFFFFFF;
    // Check both old and new magic words during transition
    if (magic == GSL_CSHM_MAGIC_WORD_V1 || 
        (magic & 0xFFFF) == GSL_CSHM_MAGIC_WORD_V2) {
        return true;
    }
    return false;
}

static inline uint8_t to_gsl_cshm_indx(gsl_mem_id_t mem_id)
{
    uint32_t magic = (uintptr_t)mem_id & 0xFFFFFF;
    // Detect version and use appropriate shift
    if (magic == GSL_CSHM_MAGIC_WORD_V1) {
        return ((uintptr_t)mem_id >> GSL_CSHM_IDX_SHIFT_V1) & 0xff;
    }
    return ((uintptr_t)mem_id >> GSL_CSHM_IDX_SHIFT_V2) & 0xff;
}

⚠️ This review was generated using AI assistance. Please verify all suggestions before applying.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qualcomm AI Review

Comment thread gsl/inc/gsl_cshm_mgr.h
Comment thread gsl/inc/gsl_cshm_mgr.h
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@qualcomm-ai-code-review-assistant

Copy link
Copy Markdown

Qualcomm AI Review

Click to expand Code Review

Reviewed commit: 4de3d56 "args: update header for force recognition in batching mode

Update spf headers to support force recognition change

Signed-off-by: ffrancis ffrancis@qti.qualcomm.com"

Pull Request Overview

This PR introduces support for batch drain completion notifications in the detection engine API, specifically for Force Recognition in batching mode. The changes add a new event type (KEY_ID_BATCH_DRAIN_COMPLETE) and associated data structures to notify clients when partial batch drains complete in the History Buffer module.

Files Changed Summary

File Lines Changed Issues Found Highest Severity
spf/api/modules/detection_cmn_api.h +45, -13 0 N/A
spf/api/modules/history_buffer_api.h +25, -13 0 N/A

Key Changes

  1. Added KEY_ID_BATCH_DRAIN_COMPLETE enum value to detection_engine_event_key_id_info_t
  2. Added bitfield configuration for batch drain complete info in param_id_detection_engine_generic_event_cfg_t
  3. Introduced new structure batch_drain_complete_info_t with drain completion flag
  4. Added PARAM_ID_HISTORY_BUFFER_FORCE_DRAIN_BATCH parameter to trigger forced batch drains

Critical Issues

No critical issues identified. The changes are primarily additive and follow existing patterns in the codebase.


⚠️ This review was generated using AI assistance. Please verify all suggestions before applying.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qualcomm AI Review

sarath varma ganapathiraju and others added 2 commits July 31, 2026 14:45
Reduce GSL_CSHM_MAGIC_WORD from 24-bit (0x47534D) to 16-bit (0x534D),
update the mask macro to GSL_CSHM_MAGIC_WORD_MASK (0xFFFF), and adjust
GSL_CSHM_IDX_SHIFT from 24 to 16 to match the new encoding width.

Also rename GSL_MAGIC_WORD_MASK to GSL_CSHM_MAGIC_WORD_MASK for
consistency with the GSL_CSHM_ naming convention, and fix missing
newline at end of file.

Signed-off-by: ffrancis <ffrancis@qti.qualcomm.com>
Update spf headers to support force recognition change

Signed-off-by: ffrancis <ffrancis@qti.qualcomm.com>
@qualcomm-ai-code-review-assistant

Copy link
Copy Markdown

Qualcomm AI Review

Click to expand Code Review

Reviewed commit: 0307aee "args: update header for force recognition in batching mode

Update spf headers to support force recognition change

Signed-off-by: ffrancis ffrancis@qti.qualcomm.com"

Pull Request Overview

This PR introduces support for batch drain completion notifications in the detection engine API, specifically for Force Recognition in batching mode. The changes add a new event type (KEY_ID_BATCH_DRAIN_COMPLETE) and associated data structures to notify clients when partial batch drains complete in the History Buffer module.

Files Changed Summary

File Lines Changed Issues Found Highest Severity
spf/api/modules/detection_cmn_api.h +45, -13 1 Medium
spf/api/modules/history_buffer_api.h +25, -13 0 N/A

Key Changes

  1. Added KEY_ID_BATCH_DRAIN_COMPLETE enum value to detection_engine_event_key_id_info_t
  2. Added bitfield configuration for batch drain complete info in param_id_detection_engine_generic_event_cfg_t
  3. Introduced new structure batch_drain_complete_info_t with drain completion flag
  4. Added PARAM_ID_HISTORY_BUFFER_FORCE_DRAIN_BATCH parameter to trigger forced batch draining

Critical Issues

No critical issues identified. The changes are primarily additive and follow existing patterns in the codebase. One medium-severity issue related to validation logic has been identified.

[FUNCTIONALITY] Missing validation for drain_complete field - Medium Severity

The batch_drain_complete_info_t structure defines drain_complete with a range constraint of {1..1} (always set to 1), but this creates a potential issue:

  1. Inflexible Design: If the field can only ever be 1, it provides no useful information and wastes 4 bytes
  2. No Runtime Validation: There's no mechanism to validate that the value is actually 1 when received
  3. Future Extensibility: If error conditions need to be communicated later, the design would need breaking changes

Recommendation: Either:

  • Remove the field entirely if it's always 1 (use presence of the event itself as the signal)
  • Or expand the range to support error codes (e.g., 0=error, 1=success) for better extensibility

Fixed Code Snippet:

/* Option 1: Remove redundant field */
struct batch_drain_complete_info_t
{
   uint32_t status;
   /**< @h2xmle_description {Status of batch drain operation. 0=error, 1=success}
        @h2xmle_range         {0..1}
        @h2xmle_default       {1} */
};

⚠️ This review was generated using AI assistance. Please verify all suggestions before applying.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qualcomm AI Review

Comment thread spf/api/modules/detection_cmn_api.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants