6.3.2-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 252/694 arm64: dts: qcom: msm8994-kitakami: drop unit address from PMI8994 regulator
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 3555dd528ba9c08d6ccd56239c695dbeac3b63e3 ]
The PMIC regulators are not supposed to have unit addresses.
--- arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi +1 -2
@@ -173,8 +173,7 @@ * power domain.. which still isn't enough and forces us to bind * OXILI_CX and OXILI_GX together! */ - vdd_gfx: s2@1700 { - reg = <0x1700 0x100>; + vdd_gfx: s2 { regulator-name = "VDD_GFX"; regulator-min-microvolt = <980000>; regulator-max-microvolt = <980000>;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 253/694 arm64: dts: qcom: msm8994-msft-lumia-octagon: drop unit address from PMI8994 regulator
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 7a202df0f3eed006e4a9e7c06d62cf67be56c14c ]
The PMIC regulators are not supposed to have unit addresses.
--- arch/arm64/boot/dts/qcom/msm8994-msft-lumia-octagon.dtsi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/msm8994-msft-lumia-octagon.dtsi +1 -2
@@ -542,8 +542,7 @@ }; &pmi8994_spmi_regulators { - vdd_gfx: s2@1700 { - reg = <0x1700 0x100>; + vdd_gfx: s2 { regulator-min-microvolt = <980000>; regulator-max-microvolt = <980000>; };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 254/694 arm64: dts: qcom: apq8096-db820c: drop unit address from PMI8994 regulator
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit ec57cbce1a6d9384f8ac1ff966b204dc262f4927 ]
The PMIC regulators are not supposed to have unit addresses.
--- arch/arm64/boot/dts/qcom/apq8096-db820c.dts | 3 +-- arch/arm64/boot/dts/qcom/pmi8994.dtsi | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-)
arch/arm64/boot/dts/qcom/apq8096-db820c.dts +1 -2
@@ -706,8 +706,7 @@ &pmi8994_spmi_regulators { vdd_s2-supply = <&vph_pwr>; - vdd_gfx: s2@1700 { - reg = <0x1700 0x100>; + vdd_gfx: s2 { regulator-name = "VDD_GFX"; regulator-min-microvolt = <980000>; regulator-max-microvolt = <980000>;
arch/arm64/boot/dts/qcom/pmi8994.dtsi +0 -2
@@ -49,8 +49,6 @@ pmi8994_spmi_regulators: regulators { compatible = "qcom,pmi8994-regulators"; - #address-cells = <1>; - #size-cells = <1>; }; pmi8994_wled: wled@d800 {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 255/694 arm64: dts: qcom: sc8280xp: correct Soundwire wakeup interrupt name
In reply to Greg Kroah-HartmanFrom: Krzysztof Kozlowski <[email protected]>
[ Upstream commit 894e258b6a38922f9860a20ca07cf2f745e3b090 ]
The bindings expect second Soundwire interrupt to be "wakeup" (Linux driver takes by index):
sc8280xp-crd.dtb: soundwire-controller@3330000: interrupt-names:1: 'wakeup' was expected
--- arch/arm64/boot/dts/qcom/sc8280xp.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sc8280xp.dtsi +1 -1
@@ -2598,7 +2598,7 @@ reg = <0 0x03330000 0 0x2000>; interrupts-extended = <&intc GIC_SPI 959 IRQ_TYPE_LEVEL_HIGH>, <&intc GIC_SPI 520 IRQ_TYPE_LEVEL_HIGH>; - interrupt-names = "core", "wake"; + interrupt-names = "core", "wakeup"; clocks = <&txmacro>; clock-names = "iface";
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 256/694 drm/i915/pxp: Invalidate all PXP fw sessions during teardown
In reply to Greg Kroah-HartmanFrom: Alan Previn <[email protected]>
[ Upstream commit d374c047b38e9f1130308aae207dc44045cd5cac ]
A gap was recently discovered where if an application did not invalidate all of the stream keys (intentionally or not), and the driver did a full PXP global teardown on the GT subsystem, we find that future session creation would fail on the security firmware's side of the equation. i915 is the entity that needs ensure the sessions' state across both iGT and security firmware are at a known clean point when performing a full global teardown.
Architecturally speaking, i915 should inspect all active sessions and submit the invalidate-stream-key PXP command to the security firmware for each of them. However, for the upstream i915 driver we only support the arbitration session that can be created so that will be the only session we will cleanup.
Stable-dep-of: 69e6dd149212 ("drm/i915/pxp: limit drm-errors or warning on firmware API failures")
--- drivers/gpu/drm/i915/pxp/intel_pxp.h | 1 + .../drm/i915/pxp/intel_pxp_cmd_interface_42.h | 15 ++++++++ .../i915/pxp/intel_pxp_cmd_interface_cmn.h | 3 ++ drivers/gpu/drm/i915/pxp/intel_pxp_session.c | 2 ++ drivers/gpu/drm/i915/pxp/intel_pxp_tee.c | 35 +++++++++++++++++++ 5 files changed, 56 insertions(+)
drivers/gpu/drm/i915/pxp/intel_pxp.h +1 -0
@@ -24,6 +24,7 @@ void intel_pxp_init_hw(struct intel_pxp *pxp);void intel_pxp_fini_hw (struct intel_pxp *pxp);void intel_pxp_mark_termination_in_progress (struct intel_pxp *pxp); +void intel_pxp_tee_end_arb_fw_session (struct intel_pxp *pxp,u32 arb_session_id);int intel_pxp_start (struct intel_pxp *pxp);
drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_42.h +15 -0
@@ -12,6 +12,9 @@/* PXP-Opcode for Init Session */ #define PXP42_CMDID_INIT_SESSION 0x1e +/* PXP-Opcode for Invalidate Stream Key */ +#define PXP42_CMDID_INVALIDATE_STREAM_KEY 0x00000007 +/* PXP-Input-Packet: Init Session (Arb-Session) */ struct pxp42_create_arb_in {struct pxp_cmd_header header;
@@ -25,4 +28,16 @@ struct pxp42_create_arb_out { struct pxp_cmd_header header; } __packed; +/* PXP-Input-Packet: Invalidate Stream Key */ +struct pxp42_inv_stream_key_in { +struct pxp_cmd_header header; +u32 rsvd[3 ]; +} __packed; + +/* PXP-Output-Packet: Invalidate Stream Key */ +struct pxp42_inv_stream_key_out { +struct pxp_cmd_header header; +u32 rsvd; +} __packed; +#endif /* __INTEL_PXP_FW_INTERFACE_42_H__ */
drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_cmn.h +3 -0
@@ -28,6 +28,9 @@ struct pxp_cmd_header {union {u32 status;/* out */ u32 stream_id;/* in */ +#define PXP_CMDHDR_EXTDATA_SESSION_VALID GENMASK(0, 0) +#define PXP_CMDHDR_EXTDATA_APP_TYPE GENMASK(1, 1) +#define PXP_CMDHDR_EXTDATA_SESSION_ID GENMASK(17, 2) };/* Length of the message (excluding the header) */ u32 buffer_len;
drivers/gpu/drm/i915/pxp/intel_pxp_session.c +2 -0
@@ -110,6 +110,8 @@ static int pxp_terminate_arb_session_and_global(struct intel_pxp *pxp)intel_uncore_write (gt->uncore,PXP_GLOBAL_TERMINATE ,1 ); +intel_pxp_tee_end_arb_fw_session (pxp,ARB_SESSION ); +return ret; }
drivers/gpu/drm/i915/pxp/intel_pxp_tee.c +35 -0
@@ -308,3 +308,38 @@ int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,return ret; } + +void intel_pxp_tee_end_arb_fw_session (struct intel_pxp *pxp,u32 session_id) +{ +struct drm_i915_private *i915 = pxp->ctrl_gt->i915; +struct pxp42_inv_stream_key_in msg_in = {0 }; +struct pxp42_inv_stream_key_out msg_out = {0 }; +int ret, trials =0 ; + +try_again: +memset (&msg_in,0 ,sizeof (msg_in)); +memset (&msg_out,0 ,sizeof (msg_out)); + msg_in.header.api_version =PXP_APIVER (4 ,2 ); + msg_in.header.command_id =PXP42_CMDID_INVALIDATE_STREAM_KEY ; + msg_in.header.buffer_len =sizeof (msg_in) -sizeof (msg_in.header); + + msg_in.header.stream_id =FIELD_PREP (PXP_CMDHDR_EXTDATA_SESSION_VALID ,1 ); + msg_in.header.stream_id |=FIELD_PREP (PXP_CMDHDR_EXTDATA_APP_TYPE ,0 ); + msg_in.header.stream_id |=FIELD_PREP (PXP_CMDHDR_EXTDATA_SESSION_ID , session_id); + + ret =intel_pxp_tee_io_message (pxp, + &msg_in,sizeof (msg_in), + &msg_out,sizeof (msg_out), +NULL ); + +/* Cleanup coherency between GT and Firmware is critical, so try again if it fails */ +if ((ret || msg_out.header.status !=0x0 ) && ++trials <3 ) + goto try_again; + +if (ret) +drm_err (&i915->drm,"Failed to send tee msg for inv-stream-key-%d, ret=[%d]\n" , + session_id, ret); +else if (msg_out.header.status !=0x0 ) +drm_warn (&i915->drm,"PXP firmware failed inv-stream-key-%d with status 0x%08x\n" , + session_id, msg_out.header.status); +}
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 257/694 drm/i915/pxp: limit drm-errors or warning on firmware API failures
In reply to Greg Kroah-HartmanFrom: Alan Previn <[email protected]>
[ Upstream commit 69e6dd149212cdd681201352a79e6634665004e8 ]
MESA driver is creating protected context on every driver handle creation to query caps bits for app. So when running CI tests, they are observing hundreds of drm_errors when enabling PXP in .config but using SOC fusing or BIOS configuration that cannot support PXP sessions.
The fixes tag referenced below was to resolve a related issue where we wanted to silence error messages, but that case was due to outdated IFWI (firmware) that definitely needed an upgrade and was, at that point, considered a one-off case as opposed to today's realization that default CI was enabling PXP in kernel config for all testing.
So with this patch, let's strike a balance between issues that is critical but are root-caused from HW/platform gaps (louder drm-warn but just ONCE) vs other cases where it could also come from session state machine (which cannot be a WARN_ONCE since it can be triggered due to runtime operation events).
Let's use helpers for these so as more functions are added in future features / HW (or as FW designers continue to bless upstreaming of the error codes and meanings), we only need to update the helpers.
NOTE: Don't completely remove FW errors (via drm_debug) or else cusomer apps that really needs to know that content protection failed won't be aware of it.
v2: - Add fixes tag (Trvtko)
v3: - Break multi-line drm_dbg strings into separate drm_dbg (Daniele)
- Fix couple of typecasting nits (Daniele)
v4: - Unsuccessful PXP FW cmd due to platform configuration shouldn't
use drm_WARN_once (Tvrtko), Switched to use drm_info_once.
v5: - Added "reported-and-tested" by Eero.
--- .../i915/pxp/intel_pxp_cmd_interface_cmn.h | 3 + drivers/gpu/drm/i915/pxp/intel_pxp_session.c | 2 +- drivers/gpu/drm/i915/pxp/intel_pxp_tee.c | 77 +++++++++++++++---- 3 files changed, 67 insertions(+), 15 deletions(-)
drivers/gpu/drm/i915/pxp/intel_pxp_cmd_interface_cmn.h +3 -0
@@ -18,6 +18,9 @@enum pxp_status {PXP_STATUS_SUCCESS =0x0 ,PXP_STATUS_ERROR_API_VERSION =0x1002 , +PXP_STATUS_NOT_READY =0x100e , +PXP_STATUS_PLATFCONFIG_KF1_NOVERIF =0x101a , +PXP_STATUS_PLATFCONFIG_KF1_BAD =0x101f ,PXP_STATUS_OP_NOT_PERMITTED =0x4013 };
drivers/gpu/drm/i915/pxp/intel_pxp_session.c +1 -1
@@ -74,7 +74,7 @@ static int pxp_create_arb_session(struct intel_pxp *pxp) ret =pxp_wait_for_session_state (pxp,ARB_SESSION , true);if (ret) { -drm_err (>->i915->drm,"arb session failed to go in play\n" ); +drm_dbg (>->i915->drm,"arb session failed to go in play\n" );return ret; }drm_dbg (>->i915->drm,"PXP ARB session is alive\n" );
drivers/gpu/drm/i915/pxp/intel_pxp_tee.c +63 -14
94 lines not on this page · raw message
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 258/694 arm64: dts: rockchip: Assign PLL_PPLL clock rate to 1.1 GHz on rk3588s
In reply to Greg Kroah-HartmanFrom: Cristian Ciocaltea <[email protected]>
[ Upstream commit b46a22dea7530cf530a45c6b84c03300083b813d ]
The clock rate for PLL_PPLL has been wrongly initialized to 100 MHz instead of 1.1 GHz. Fix it.
--- arch/arm64/boot/dts/rockchip/rk3588s.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/rockchip/rk3588s.dtsi +1 -1
@@ -423,7 +423,7 @@ <&cru ACLK_BUS_ROOT>, <&cru CLK_150M_SRC>, <&cru CLK_GPU>; assigned-clock-rates = - <100000000>, <786432000>, + <1100000000>, <786432000>, <850000000>, <1188000000>, <702000000>, <400000000>, <500000000>,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 259/694 drm/ttm/pool: Fix ttm_pool_alloc error path
In reply to Greg Kroah-HartmanFrom: Thomas Hellström <[email protected]>
[ Upstream commit 379989e7cbdc7aa7496a00ee286ec146c7599cf0 ]
When hitting an error, the error path forgot to unmap dma mappings and could call set_pages_wb() on already uncached pages.
Fix this by introducing a common ttm_pool_free_range() function that does the right thing.
v2:
- Simplify that common function (Christian König)
v3:
- Rename that common function to ttm_pool_free_range() (Christian König)
--- drivers/gpu/drm/ttm/ttm_pool.c | 81 +++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 30 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +51 -30
@@ -367,6 +367,43 @@ static int ttm_pool_page_allocated(struct ttm_pool *pool, unsigned int order,return 0 ; } +/** +* ttm_pool_free_range() - Free a range of TTM pages +* @pool: The pool used for allocating. +* @tt: The struct ttm_tt holding the page pointers. +* @caching: The page caching mode used by the range. +* @start_page: index for first page to free. +* @end_page: index for last page to free + 1. +* +* During allocation the ttm_tt page-vector may be populated with ranges of +* pages with different attributes if allocation hit an error without being +* able to completely fulfill the allocation. This function can be used +* to free these individual ranges. +*/ +static void ttm_pool_free_range (struct ttm_pool *pool,struct ttm_tt *tt, +enum ttm_caching caching, +pgoff_t start_page,pgoff_t end_page) +{ +struct page **pages = tt->pages; +unsigned int order; +pgoff_t i, nr; + +for (i = start_page; i < end_page; i += nr, pages += nr) { +struct ttm_pool_type *pt =NULL ; + + order =ttm_pool_page_order (pool, *pages); + nr = (1UL << order); +if (tt->dma_address) +ttm_pool_unmap (pool, tt->dma_address[i], nr); + + pt =ttm_pool_select_type (pool, caching, order); +if (pt) +ttm_pool_type_give (pt, *pages); +else +ttm_pool_free_page (pool, caching, order, *pages); + } +} +/** * ttm_pool_alloc - Fill a ttm_tt object *
@@ -382,12 +419,14 @@ static int ttm_pool_page_allocated(struct ttm_pool *pool, unsigned int order,int ttm_pool_alloc (struct ttm_pool *pool,struct ttm_tt *tt,struct ttm_operation_ctx *ctx) { -unsigned long num_pages = tt->num_pages; +pgoff_t num_pages = tt->num_pages;dma_addr_t *dma_addr = tt->dma_address;struct page **caching = tt->pages;struct page **pages = tt->pages; +enum ttm_caching page_caching;gfp_t gfp_flags =GFP_USER ; -unsigned int i, order; +pgoff_t caching_divide; +unsigned int order;struct page *p;int r;
@@ -410,6 +449,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, order = min_t(unsigned int, order, __fls(num_pages))) {struct ttm_pool_type *pt; + page_caching = tt->caching; pt =ttm_pool_select_type (pool, tt->caching, order); p = pt ?ttm_pool_type_take (pt) :NULL ;if (p) {
@@ -418,6 +458,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,if (r) goto error_free_page; + caching = pages; do { r = ttm_pool_page_allocated(pool, order, p, &dma_addr,
@@ -426,14 +467,15 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,if (r) goto error_free_page; + caching = pages;if (num_pages < (1 << order))break ; p =ttm_pool_type_take (pt); }while (p); - caching = pages; } + page_caching = ttm_cached;while (num_pages >= (1 << order) && (p =ttm_pool_alloc_page (pool, gfp_flags, order))) {
@@ -442,6 +484,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, tt->caching);if (r) goto error_free_page; + caching = pages; } r =ttm_pool_page_allocated (pool, order, p, &dma_addr, &num_pages, &pages);
@@ -468,15 +511,13 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,return 0 ; error_free_page: -ttm_pool_free_page (pool, tt->caching, order, p); +ttm_pool_free_page (pool, page_caching, order, p); error_free_all: num_pages = tt->num_pages - num_pages; -for (i =0 ; i < num_pages; ) { - order =ttm_pool_page_order (pool, tt->pages[i]); -ttm_pool_free_page (pool, tt->caching, order, tt->pages[i]); - i +=1 << order; - } + caching_divide = caching - tt->pages; +ttm_pool_free_range (pool, tt, tt->caching,0 , caching_divide); +ttm_pool_free_range (pool, tt, ttm_cached, caching_divide, num_pages);return r; }
@@ -492,27 +533,7 @@ EXPORT_SYMBOL(ttm_pool_alloc);*/ void ttm_pool_free (struct ttm_pool *pool,struct ttm_tt *tt) { -unsigned int i; - -for (i =0 ; i < tt->num_pages; ) { -struct page *p = tt->pages[i]; -unsigned int order, num_pages; -struct ttm_pool_type *pt; - - order =ttm_pool_page_order (pool, p); - num_pages =1ULL << order; -if (tt->dma_address) -ttm_pool_unmap (pool, tt->dma_address[i], num_pages); - - pt =ttm_pool_select_type (pool, tt->caching, order); -if (pt) -ttm_pool_type_give (pt, tt->pages[i]); -else -ttm_pool_free_page (pool, tt->caching, order, - tt->pages[i]); - - i += num_pages; - } +ttm_pool_free_range (pool, tt, tt->caching,0 , tt->num_pages);while (atomic_long_read (&allocated_pages) > page_pool_size)ttm_pool_shrink ();
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 260/694 regulator: core: Consistently set mutex_owner when using ww_mutex_lock_slow()
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit b83a1772be854f87602de14726737d3e5b06e1f4 ]
When a codepath locks a rdev using ww_mutex_lock_slow() directly then that codepath is responsible for incrementing the "ref_cnt" and also setting the "mutex_owner" to "current".
The regulator core consistently got that right for "ref_cnt" but didn't always get it right for "mutex_owner". Let's fix this.
It's unlikely that this truly matters because the "mutex_owner" is only needed if we're going to do subsequent locking of the same rdev. However, even though it's not truly needed it seems less surprising if we consistently set "mutex_owner" properly.
--- drivers/regulator/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/regulator/core.c +2 -0
@@ -334,6 +334,7 @@ static void regulator_lock_dependent(struct regulator_dev *rdev,ww_mutex_lock_slow (&new_contended_rdev->mutex, ww_ctx); old_contended_rdev = new_contended_rdev; old_contended_rdev->ref_cnt++; + old_contended_rdev->mutex_owner = current; } err = regulator_lock_recursive(rdev,
@@ -6048,6 +6049,7 @@ static void regulator_summary_lock(struct ww_acquire_ctx *ww_ctx)ww_mutex_lock_slow (&new_contended_rdev->mutex, ww_ctx); old_contended_rdev = new_contended_rdev; old_contended_rdev->ref_cnt++; + old_contended_rdev->mutex_owner = current; } err = regulator_summary_lock_all(ww_ctx,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 261/694 regulator: core: Avoid lockdep reports when resolving supplies
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit cba6cfdc7c3f1516f0d08ddfb24e689af0932573 ]
An automated bot told me that there was a potential lockdep problem
with regulators. This was on the chromeos-5.15 kernel, but I see
nothing that would be different downstream compared to upstream. The
bot said:
============================================
WARNING: possible recursive locking detected 5.15.104-lockdep-17461-gc1e499ed6604 #1 Not tainted
--------------------------------------------
kworker/u16:4/115 is trying to acquire lock:
ffffff8083110170 (regulator_ww_class_mutex){+.+.}-{3:3}, at: create_regulator+0x398/0x7ec
but task is already holding lock:
ffffff808378e170 (regulator_ww_class_mutex){+.+.}-{3:3}, at: ww_mutex_trylock+0x3c/0x7b8
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(regulator_ww_class_mutex);
lock(regulator_ww_class_mutex);*** DEADLOCK ***
May be due to missing lock nesting notation
4 locks held by kworker/u16:4/115:
#0: ffffff808006a948 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work+0x520/0x1348 #1: ffffffc00e0a7cc0 ((work_completion)(&entry->work)){+.+.}-{0:0}, at: process_one_work+0x55c/0x1348 #2: ffffff80828a2260 (&dev->mutex){....}-{3:3}, at: __device_attach_async_helper+0xd0/0x2a4 #3: ffffff808378e170 (regulator_ww_class_mutex){+.+.}-{3:3}, at: ww_mutex_trylock+0x3c/0x7b8
stack backtrace: CPU: 2 PID: 115 Comm: kworker/u16:4 Not tainted 5.15.104-lockdep-17461-gc1e499ed6604 #1 9292e52fa83c0e23762b2b3aa1bacf5787a4d5da Hardware name: Google Quackingstick (rev0+) (DT) Workqueue: events_unbound async_run_entry_fn Call trace: dump_backtrace+0x0/0x4ec show_stack+0x34/0x50 dump_stack_lvl+0xdc/0x11c dump_stack+0x1c/0x48 __lock_acquire+0x16d4/0x6c74 lock_acquire+0x208/0x750 __mutex_lock_common+0x11c/0x11f8 ww_mutex_lock+0xc0/0x440 create_regulator+0x398/0x7ec regulator_resolve_supply+0x654/0x7c4 regulator_register_resolve_supply+0x30/0x120 class_for_each_device+0x1b8/0x230 regulator_register+0x17a4/0x1f40 devm_regulator_register+0x60/0xd0 reg_fixed_voltage_probe+0x728/0xaec platform_probe+0x150/0x1c8 really_probe+0x274/0xa20 __driver_probe_device+0x1dc/0x3f4 driver_probe_device+0x78/0x1c0 __device_attach_driver+0x1ac/0x2c8 bus_for_each_drv+0x11c/0x190 __device_attach_async_helper+0x1e4/0x2a4 async_run_entry_fn+0xa0/0x3ac process_one_work+0x638/0x1348 worker_thread+0x4a8/0x9c4 kthread+0x2e4/0x3a0 ret_from_fork+0x10/0x20
The problem was first reported soon after we made many of the regulators probe asynchronously, though nothing I've seen implies that the problems couldn't have also happened even without that.
I haven't personally been able to reproduce the lockdep issue, but the issue does look somewhat legitimate. Specifically, it looks like in regulator_resolve_supply() we are holding a "rdev" lock while calling set_supply() -> create_regulator() which grabs the lock of a _different_ "rdev" (the one for our supply). This is not necessarily safe from a lockdep perspective since there is no documented ordering between these two locks.
In reality, we should always be locking a regulator before the supplying regulator, so I don't expect there to be any real deadlocks in practice. However, the regulator framework in general doesn't express this to lockdep.
Let's fix the issue by simply grabbing the two locks involved in the same way we grab multiple locks elsewhere in the regulator framework:
using the "wound/wait" mechanisms.
--- drivers/regulator/core.c | 91 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 8 deletions(-)
drivers/regulator/core.c +83 -8
@@ -207,6 +207,78 @@ static void regulator_unlock(struct regulator_dev *rdev)mutex_unlock (®ulator_nesting_mutex); } +/** +* regulator_lock_two - lock two regulators +* @rdev1: first regulator +* @rdev2: second regulator +* @ww_ctx: w/w mutex acquire context +* +* Locks both rdevs using the regulator_ww_class. +*/ +static void regulator_lock_two (struct regulator_dev *rdev1, +struct regulator_dev *rdev2, +struct ww_acquire_ctx *ww_ctx) +{ +struct regulator_dev *tmp; +int ret; + +ww_acquire_init (ww_ctx, ®ulator_ww_class); + +/* Try to just grab both of them */ + ret =regulator_lock_nested (rdev1, ww_ctx); +WARN_ON (ret); + ret =regulator_lock_nested (rdev2, ww_ctx); +if (ret != -EDEADLOCK ) { +WARN_ON (ret); + goto exit; + } + +while (true) { +/* +* Start of loop: rdev1 was locked and rdev2 was contended. +* Need to unlock rdev1, slowly lock rdev2, then try rdev1 +* again. +*/ +regulator_unlock (rdev1); + +ww_mutex_lock_slow (&rdev2->mutex, ww_ctx); + rdev2->ref_cnt++; + rdev2->mutex_owner = current; + ret =regulator_lock_nested (rdev1, ww_ctx); + +if (ret == -EDEADLOCK ) { +/* More contention; swap which needs to be slow */ + tmp = rdev1; + rdev1 = rdev2; + rdev2 = tmp; + }else { +WARN_ON (ret); +break ; + } + } + +exit: +ww_acquire_done (ww_ctx); +} + +/** +* regulator_unlock_two - unlock two regulators +* @rdev1: first regulator +* @rdev2: second regulator +* @ww_ctx: w/w mutex acquire context +* +* The inverse of regulator_lock_two(). +*/ + +static void regulator_unlock_two (struct regulator_dev *rdev1, +struct regulator_dev *rdev2, +struct ww_acquire_ctx *ww_ctx) +{ +regulator_unlock (rdev2); +regulator_unlock (rdev1); +ww_acquire_fini (ww_ctx); +} +static bool regulator_supply_is_couple (struct regulator_dev *rdev) {struct regulator_dev *c_rdev;
@@ -1627,8 +1699,8 @@ static int set_machine_constraints(struct regulator_dev *rdev)/** * set_supply - set regulator supply regulator -* @rdev: regulator name -* @supply_rdev: supply regulator name +* @rdev: regulator (locked) +* @supply_rdev: supply regulator (locked)) * * Called by platform initialisation code to set the supply regulator for this * regulator. This ensures that a regulators supply will also be enabled by the
@@ -1800,6 +1872,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,struct regulator *regulator;int err =0 ; +lockdep_assert_held_once (&rdev->mutex.base); +if (dev) {char buf[REG_STR_SIZE ];int size;
@@ -1827,9 +1901,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, regulator->rdev = rdev; regulator->supply_name = supply_name; -regulator_lock (rdev);list_add (®ulator->list, &rdev->consumer_list); -regulator_unlock (rdev);if (dev) { regulator->dev = dev;
@@ -1995,6 +2067,7 @@ static int regulator_resolve_supply(struct regulator_dev *rdev) {struct regulator_dev *r;struct device *dev = rdev->dev.parent; +struct ww_acquire_ctx ww_ctx;int ret =0 ;/* No supply to resolve? */
@@ -2061,23 +2134,23 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)* between rdev->supply null check and setting rdev->supply in * set_supply() from concurrent tasks. */ -regulator_lock (rdev); +regulator_lock_two (rdev, r, &ww_ctx);/* Supply just resolved by a concurrent task? */ if (rdev->supply) { -regulator_unlock (rdev); +regulator_unlock_two (rdev, r, &ww_ctx);put_device (&r->dev); goto out; } ret =set_supply (rdev, r);if (ret <0 ) { -regulator_unlock (rdev); +regulator_unlock_two (rdev, r, &ww_ctx);put_device (&r->dev); goto out; } -regulator_unlock (rdev); +regulator_unlock_two (rdev, r, &ww_ctx);/* * In set_machine_constraints() we may have turned this regulator on
@@ -2190,7 +2263,9 @@ struct regulator *_regulator_get(struct device *dev, const char *id,return regulator; } +regulator_lock (rdev); regulator =create_regulator (rdev, dev, id); +regulator_unlock (rdev);if (regulator ==NULL ) { regulator =ERR_PTR (-ENOMEM );module_put (rdev->owner);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 262/694 Revert "drm/msm: Add missing check and destroy for alloc_ordered_workqueue"
In reply to Greg Kroah-HartmanFrom: Johan Hovold <[email protected]>
[ Upstream commit dfa70344d1b5f5ff08525a8c872c8dd5e82fc5d9 ]
This reverts commit 643b7d0869cc7f1f7a5ac7ca6bd25d88f54e31d0.
A recent patch that tried to fix up the msm_drm_init() paths with respect to the workqueue but only ended up making things worse:
First, the newly added calls to msm_drm_uninit() on early errors would trigger NULL-pointer dereferences, for example, as the kms pointer would not have been initialised. (Note that these paths were also modified by a second broken error handling patch which in effect cancelled out this part when merged.)
Second, the newly added allocation sanity check would still leak the previously allocated drm device.
Instead of trying to salvage what was badly broken (and clearly not tested), let's revert the bad commit so that clean and backportable fixes can be added in its place.
Patchwork: https://patchwork.freedesktop.org/patch/525107/
--- drivers/gpu/drm/msm/msm_drv.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +0 -2
@@ -420,8 +420,6 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) priv->dev = ddev; priv->wq =alloc_ordered_workqueue ("msm" ,0 ); -if (!priv->wq) -return -ENOMEM ;INIT_LIST_HEAD (&priv->objects);mutex_init (&priv->obj_lock);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 263/694 Revert "drm/msm: Fix failure paths in msm_drm_init()"
In reply to Greg Kroah-HartmanFrom: Johan Hovold <[email protected]>
[ Upstream commit 652eadfde81031c7b3d8b21bdbcfdd6eb217dec8 ]
This reverts commit 8636500300a01740d92b345c680b036b94555b1b.
A recent commit tried to address a drm device leak in the early msm_drm_uninit() error paths but ended up making things worse.
Specifically, it moved the drm device reference put in msm_drm_uninit() to msm_drm_init() which means that the drm would now be leaked on normal unbind.
For reasons that were never spelled out, it also added kms NULL pointer checks to a couple of helper functions that had nothing to do with the paths modified by the patch.
Instead of trying to salvage this incrementally, let's revert the bad commit so that clean and backportable fixes can be added in its place.
Patchwork: https://patchwork.freedesktop.org/patch/525092/
--- drivers/gpu/drm/msm/disp/msm_disp_snapshot.c | 3 --- drivers/gpu/drm/msm/msm_drv.c | 11 ++++------- 2 files changed, 4 insertions(+), 10 deletions(-)
drivers/gpu/drm/msm/disp/msm_disp_snapshot.c +0 -3
@@ -129,9 +129,6 @@ void msm_disp_snapshot_destroy(struct drm_device *drm_dev) } priv = drm_dev->dev_private; -if (!priv->kms) -return ; - kms = priv->kms;if (kms->dump_worker)
drivers/gpu/drm/msm/msm_drv.c +4 -7
@@ -150,9 +150,6 @@ static void msm_irq_uninstall(struct drm_device *dev)struct msm_drm_private *priv = dev->dev_private;struct msm_kms *kms = priv->kms; -if (!priv->kms) -return ; - kms->funcs->irq_uninstall (kms);if (kms->irq_requested)free_irq (kms->irq, dev);
@@ -270,6 +267,8 @@ static int msm_drm_uninit(struct device *dev)component_unbind_all (dev, ddev); ddev->dev_private =NULL ; +drm_dev_put (ddev); +destroy_workqueue (priv->wq);return 0 ;
@@ -442,12 +441,12 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) ret =msm_init_vram (ddev);if (ret) - goto err_drm_dev_put; +return ret;/* Bind all our sub-components: */ ret =component_bind_all (dev, ddev);if (ret) - goto err_drm_dev_put; +return ret;dma_set_max_seg_size (dev,UINT_MAX );
@@ -542,8 +541,6 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) err_msm_uninit:msm_drm_uninit (dev); -err_drm_dev_put: -drm_dev_put (ddev);return ret; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 264/694 drm/msm/dpu: Fix bit-shifting UB in DPU_HW_VER() macro
In reply to Greg Kroah-HartmanFrom: Geert Uytterhoeven <[email protected]>
[ Upstream commit 4760be481dc075cd13f95f4650f5d5b53b4b336d ]
With gcc-5 and CONFIG_UBSAN_SHIFT=y:
drivers/gpu/drm/msm/msm_mdss.c: In function 'msm_mdss_enable':
drivers/gpu/drm/msm/msm_mdss.c:296:2: error: case label does not reduce to an integer constant
case DPU_HW_VER_800:
^
drivers/gpu/drm/msm/msm_mdss.c:299:2: error: case label does not reduce to an integer constant
case DPU_HW_VER_810:
^
drivers/gpu/drm/msm/msm_mdss.c:300:2: error: case label does not reduce to an integer constant
case DPU_HW_VER_900:
^This happens because for major revisions 8 or greather, the non-sign bit of the major revision number is shifted into bit 31 of a signed integer, which is undefined behavior.
Fix this by casting the major revision number to unsigned int.
Patchwork: https://patchwork.freedesktop.org/patch/525152/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_catalog.h +3 -2
@@ -19,8 +19,9 @@*/ #define MAX_BLOCKS 12 -#define DPU_HW_VER (MAJOR ,MINOR ,STEP ) (((MAJOR & 0xF) << 28) |\ - ((MINOR & 0xFFF) << 16) |\ +#define DPU_HW_VER (MAJOR ,MINOR ,STEP ) \ + ((((unsigned int)MAJOR & 0xF) << 28) | \ + ((MINOR & 0xFFF) << 16) | \ (STEP & 0xFFFF))#define DPU_HW_MAJOR (rev) ((rev) >> 28)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 265/694 thermal/drivers/mediatek/lvts_thermal: Fix sensor 1 interrupt status bitmask
In reply to Greg Kroah-HartmanFrom: Chen-Yu Tsai <[email protected]>
[ Upstream commit 13f03bcd02e4b0498c8ccb066b4eddf61dee6681 ]
The binary representation for sensor 1 interrupt status was incorrectly assembled, when compared to the full table given in the same comment section. The conversion into hex was also incorrect, leading to incorrect interrupt status bitmask for sensor 1. This would cause the driver to incorrectly identify changes for sensor 1, when in fact it was sensor 0, or a sensor access time out.
Fix the binary and hex representations in the comments, and the actual bitmask macro.
--- drivers/thermal/mediatek/lvts_thermal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thermal/mediatek/lvts_thermal.c +3 -3
@@ -66,7 +66,7 @@#define LVTS_MONINT_CONF 0x9FBF7BDE#define LVTS_INT_SENSOR0 0x0009001F -#define LVTS_INT_SENSOR1 0X000881F0 +#define LVTS_INT_SENSOR1 0x001203E0#define LVTS_INT_SENSOR2 0x00247C00#define LVTS_INT_SENSOR3 0x1FC00000
@@ -393,8 +393,8 @@ static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)* => 0x1FC00000 * sensor 2 interrupt: 0000 0000 0010 0100 0111 1100 0000 0000 * => 0x00247C00 -* sensor 1 interrupt: 0000 0000 0001 0001 0000 0011 1110 0000 -* => 0X000881F0 +* sensor 1 interrupt: 0000 0000 0001 0010 0000 0011 1110 0000 +* => 0X001203E0 * sensor 0 interrupt: 0000 0000 0000 1001 0000 0000 0001 1111 * => 0x0009001F */
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 266/694 x86/apic: Fix atomic update of offset in reserve_eilvt_offset()
In reply to Greg Kroah-HartmanFrom: Uros Bizjak <[email protected]>
[ Upstream commit f96fb2df3eb31ede1b34b0521560967310267750 ]
The detection of atomic update failure in reserve_eilvt_offset() is not correct. The value returned by atomic_cmpxchg() should be compared to the old value from the location to be updated.
If these two are the same, then atomic update succeeded and "eilvt_offsets[offset]" location is updated to "new" in an atomic way.
Otherwise, the atomic update failed and it should be retried with the value from "eilvt_offsets[offset]" - exactly what atomic_try_cmpxchg() does in a correct and more optimal way.
--- arch/x86/kernel/apic/apic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/kernel/apic/apic.c +2 -3
@@ -422,10 +422,9 @@ static unsigned int reserve_eilvt_offset(int offset, unsigned int new)if (vector && !eilvt_entry_is_changeable (vector, new))/* may not change if vectors are different */ return rsvd; - rsvd =atomic_cmpxchg (&eilvt_offsets[offset], rsvd, new); - }while (rsvd != new); + }while (!atomic_try_cmpxchg (&eilvt_offsets[offset], &rsvd, new)); - rsvd &= ~APIC_EILVT_MASKED ; + rsvd = new & ~APIC_EILVT_MASKED ;if (rsvd && rsvd != vector)pr_info ("LVT offset %d assigned for vector 0x%02x\n" , offset, rsvd);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 267/694 soc: qcom: rpmh-rsc: Support RSC v3 minor versions
In reply to Greg Kroah-HartmanFrom: Tushar Nimkar <[email protected]>
[ Upstream commit 88704a0cd71909c3107561261412a5d5beb23358 ]
RSC v3 register offsets are same for all minor versions of v3. Fix a minor version check to pick correct offsets for all v3 minor versions.
--- drivers/soc/qcom/rpmh-rsc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/rpmh-rsc.c +1 -1
@@ -1073,7 +1073,7 @@ static int rpmh_rsc_probe(struct platform_device *pdev) drv->ver.minor = rsc_id & (MINOR_VER_MASK <<MINOR_VER_SHIFT ); drv->ver.minor >>=MINOR_VER_SHIFT ; -if (drv->ver.major ==3 && drv->ver.minor ==0 ) +if (drv->ver.major ==3 && drv->ver.minor >=0 ) drv->regs = rpmh_rsc_reg_offset_ver_3_0;else drv->regs = rpmh_rsc_reg_offset_ver_2_7;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 268/694 arm64: dts: qcom: msm8994-angler: Fix cont_splash_mem mapping
In reply to Greg Kroah-HartmanFrom: Petr Vorel <[email protected]>
[ Upstream commit fe88480a6be92ecbf6f205ff3a7d7e5ded0562dd ]
Angler's cont_splash_mem mapping is shorter in downstream [1], therefore 380cd3a34b7f was wrong. Obviously also 0e5ded926f2a was wrong (workaround which fixed booting at the time).
This fixes error:
[ 0.000000] memory@3401000 (0x0000000003401000--0x0000000005601000) overlaps with tzapp@4800000 (0x0000000004800000--0x0000000006100000)
--- arch/arm64/boot/dts/qcom/msm8994-huawei-angler-rev-101.dts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/msm8994-huawei-angler-rev-101.dts +6 -1
@@ -2,7 +2,7 @@ /* * Copyright (c) 2015, Huawei Inc. All rights reserved. * Copyright (c) 2016, The Linux Foundation. All rights reserved. - * Copyright (c) 2021-2022, Petr Vorel <[email protected]> + * Copyright (c) 2021-2023, Petr Vorel <[email protected]> */ /dts-v1/;
@@ -31,6 +31,11 @@ #size-cells = <2>; ranges; + cont_splash_mem: memory@3401000 { + reg = <0 0x03401000 0 0x1000000>; + no-map; + }; + tzapp_mem: tzapp@4800000 { reg = <0 0x04800000 0 0x1900000>; no-map;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 269/694 arm64: dts: qcom: msm8994-angler: removed clash with smem_region
In reply to Greg Kroah-HartmanFrom: Petr Vorel <[email protected]>
[ Upstream commit c85c8a992794dfcd7cea7a41871710c27c5592a6 ]
This fixes memory overlap error:
[ 0.000000] reserved@6300000 (0x0000000006300000--0x0000000007000000) overlaps with smem_region@6a00000 (0x0000000006a00000--0x0000000006c00000)
smem_region is the same as in downstream (qcom,smem) [1], therefore split reserved memory into two sections on either side of smem_region.
Not adding labels as it's not expected to be used.
--- arch/arm64/boot/dts/qcom/msm8992-lg-bullhead.dtsi | 5 ----- arch/arm64/boot/dts/qcom/msm8994-huawei-angler-rev-101.dts | 4 ++-- arch/arm64/boot/dts/qcom/msm8994.dtsi | 5 +++++ 3 files changed, 7 insertions(+), 7 deletions(-)
arch/arm64/boot/dts/qcom/msm8992-lg-bullhead.dtsi +0 -5
@@ -60,11 +60,6 @@ reg = <0x0 0x05000000 0x0 0x1a00000>; no-map; }; - - reserved@6c00000 { - reg = <0x0 0x06c00000 0x0 0x400000>; - no-map; - }; }; };
arch/arm64/boot/dts/qcom/msm8994-huawei-angler-rev-101.dts +2 -2
@@ -41,8 +41,8 @@ no-map; }; - removed_region: reserved@6300000 { - reg = <0 0x06300000 0 0xD00000>; + reserved@6300000 { + reg = <0 0x06300000 0 0x700000>; no-map; }; };
arch/arm64/boot/dts/qcom/msm8994.dtsi +5 -0
@@ -228,6 +228,11 @@ reg = <0 0xc9400000 0 0x3f00000>; no-map; }; + + reserved@6c00000 { + reg = <0 0x06c00000 0 0x400000>; + no-map; + }; }; smd {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 270/694 arm64: dts: sc7180: Rename qspi data12 as data23
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit d84f8f2687bdc67f20262e822b206419bcfd0038 ]
There are 4 qspi data pins: data0, data1, data2, and data3. Currently we have a shared pin state for data0 and data1 (2 lane config) and a pin state for data2 and data3 (you'd enable both this and the 2 lane state for 4 lanes). The second state is obviously misnamed. Fix it.
--- arch/arm64/boot/dts/qcom/sc7180.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sc7180.dtsi +1 -1
@@ -1540,7 +1540,7 @@ function = "qspi_data"; }; - qspi_data12: qspi-data12-state { + qspi_data23: qspi-data23-state { pins = "gpio66", "gpio67"; function = "qspi_data"; };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 271/694 arm64: dts: sc7280: Rename qspi data12 as data23
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit 14acf21c0d3f7b7298ffcd2e5b5db4a476ec6202 ]
There are 4 qspi data pins: data0, data1, data2, and data3. Currently we have a shared pin state for data0 and data1 (2 lane config) and a pin state for data2 and data3 (you'd enable both this and the 2 lane state for 4 lanes). The second state is obviously misnamed. Fix it.
--- arch/arm64/boot/dts/qcom/sc7280.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sc7280.dtsi +1 -1
@@ -4353,7 +4353,7 @@ function = "qspi_data"; }; - qspi_data12: qspi-data12-state { + qspi_data23: qspi-data23-state { pins = "gpio16", "gpio17"; function = "qspi_data"; };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 272/694 arm64: dts: sdm845: Rename qspi data12 as data23
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit 37f7349b56decc91c66f8039712e63740b1f25f9 ]
There are 4 qspi data pins: data0, data1, data2, and data3. Currently we have a shared pin state for data0 and data1 (2 lane config) and a pin state for data2 and data3 (you'd enable both this and the 2 lane state for 4 lanes). The second state is obviously misnamed. Fix it.
--- arch/arm64/boot/dts/qcom/sdm845.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/sdm845.dtsi +1 -1
@@ -2763,7 +2763,7 @@ function = "qspi_data"; }; - qspi_data12: qspi-data12-state { + qspi_data23: qspi-data23-state { pins = "gpio93", "gpio94"; function = "qspi_data"; };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 273/694 media: mtk-jpeg: Fixes jpeghw multi-core judgement
In reply to Greg Kroah-HartmanFrom: kyrie wu <[email protected]>
[ Upstream commit 75c38caf66a10983acc5a59069bfc9492c43d682 ]
some chips have multi-hw, but others have only one, modify the condition of multi-hw judgement
--- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 5 ++++- drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +4 -1
@@ -1692,7 +1692,7 @@ static int mtk_jpeg_probe(struct platform_device *pdev)return -EINVAL ; } -if (list_empty (&pdev->dev.devres_head)) { +if (!jpeg->variant->multi_core) {INIT_DELAYED_WORK (&jpeg->job_timeout_work, mtk_jpeg_job_timeout_work);
@@ -1874,6 +1874,7 @@ static const struct mtk_jpeg_variant mtk_jpeg_drvdata = { .ioctl_ops = &mtk_jpeg_enc_ioctl_ops, .out_q_default_fourcc = V4L2_PIX_FMT_YUYV, .cap_q_default_fourcc = V4L2_PIX_FMT_JPEG, + .multi_core = false, };static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = {
@@ -1885,6 +1886,7 @@ static struct mtk_jpeg_variant mtk8195_jpegenc_drvdata = { .ioctl_ops = &mtk_jpeg_enc_ioctl_ops, .out_q_default_fourcc = V4L2_PIX_FMT_YUYV, .cap_q_default_fourcc = V4L2_PIX_FMT_JPEG, + .multi_core = true, };static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = {
@@ -1896,6 +1898,7 @@ static const struct mtk_jpeg_variant mtk8195_jpegdec_drvdata = { .ioctl_ops = &mtk_jpeg_dec_ioctl_ops, .out_q_default_fourcc = V4L2_PIX_FMT_JPEG, .cap_q_default_fourcc = V4L2_PIX_FMT_YUV420M, + .multi_core = true, };#if defined(CONFIG_OF )
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h +2 -0
@@ -60,6 +60,7 @@ enum mtk_jpeg_ctx_state {* @ioctl_ops: the callback of jpeg v4l2_ioctl_ops * @out_q_default_fourcc: output queue default fourcc * @cap_q_default_fourcc: capture queue default fourcc +* @multi_core: mark jpeg hw is multi_core or not */ struct mtk_jpeg_variant {struct clk_bulk_data *clks;
@@ -74,6 +75,7 @@ struct mtk_jpeg_variant {const struct v4l2_ioctl_ops *ioctl_ops;u32 out_q_default_fourcc;u32 cap_q_default_fourcc; +bool multi_core; };struct mtk_jpeg_src_buf {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 274/694 media: mtk-jpeg: Fixes jpeg enc&dec worker sw flow
In reply to Greg Kroah-HartmanFrom: kyrie wu <[email protected]>
[ Upstream commit 86379bd9d399e2c5fd638a869af223d4910725c3 ]
1. Move removing buffer after sw setting and before hw setting in enc&dec worker to prevents the operation of removing the buffer twice if the sw setting fails.
2. Remove the redundant operation of queue work in the jpegenc irq handler because the jpegenc worker has called v4l2_m2m_job_finish to do it.
--- .../media/platform/mediatek/jpeg/mtk_jpeg_core.c | 14 +++++++------- .../media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c | 4 ---- 2 files changed, 7 insertions(+), 11 deletions(-)
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +7 -7
@@ -1025,9 +1025,6 @@ static void mtk_jpegenc_worker(struct work_struct *work)if (!dst_buf) goto getbuf_fail; -v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true);mtk_jpegenc_set_hw_param (ctx, hw_id, src_buf, dst_buf);
@@ -1045,6 +1042,9 @@ static void mtk_jpegenc_worker(struct work_struct *work) goto enc_end; } +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +schedule_delayed_work (&comp_jpeg[hw_id]->job_timeout_work,msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC ));
@@ -1220,9 +1220,6 @@ static void mtk_jpegdec_worker(struct work_struct *work)if (!dst_buf) goto getbuf_fail; -v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); -v4l2_m2m_buf_copy_metadata (src_buf, dst_buf, true); jpeg_src_buf =mtk_jpeg_vb2_to_srcbuf (&src_buf->vb2_buf); jpeg_dst_buf =mtk_jpeg_vb2_to_srcbuf (&dst_buf->vb2_buf);
@@ -1231,7 +1228,7 @@ static void mtk_jpegdec_worker(struct work_struct *work) &jpeg_src_buf->dec_param)) {mtk_jpeg_queue_src_chg_event (ctx); ctx->state =MTK_JPEG_SOURCE_CHANGE ; - goto dec_end; + goto getbuf_fail; } jpeg_src_buf->curr_ctx = ctx;
@@ -1254,6 +1251,9 @@ static void mtk_jpegdec_worker(struct work_struct *work) goto clk_end; } +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +schedule_delayed_work (&comp_jpeg[hw_id]->job_timeout_work,msecs_to_jiffies (MTK_JPEG_HW_TIMEOUT_MSEC ));
drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c +0 -4
@@ -286,10 +286,6 @@ static irqreturn_t mtk_jpegenc_hw_irq_handler(int irq, void *priv)mtk_jpegenc_put_buf (jpeg);pm_runtime_put (ctx->jpeg->dev);clk_disable_unprepare (jpeg->venc_clk.clks->clk); -if (!list_empty (&ctx->fh.m2m_ctx->out_q_ctx.rdy_queue) || - !list_empty (&ctx->fh.m2m_ctx->cap_q_ctx.rdy_queue)) { -queue_work (master_jpeg->workqueue, &ctx->jpeg_work); - } jpeg->hw_state =MTK_JPEG_HW_IDLE ;wake_up (&master_jpeg->enc_hw_wq);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 275/694 media: mediatek: vcodec: Use 4K frame size when supported by stateful decoder
In reply to Greg Kroah-HartmanFrom: Pin-yen Lin <[email protected]>
[ Upstream commit e25528e1dbe52784ac250071653104a8adc848e2 ]
After commit b018be06f3c7 ("media: mediatek: vcodec: Read max resolution from dec_capability"), the stateful video decoder driver never really sets its output frame size to 4K.
Parse the decoder capability reported by the firmware, and update the output frame size in mtk_init_vdec_params to enable 4K frame size when available.
--- .../mediatek/vcodec/mtk_vcodec_dec_stateful.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateful.c +11 -1
@@ -11,7 +11,7 @@#include "mtk_vcodec_dec_pm.h" #include "vdec_drv_if.h" -static const struct mtk_video_fmt mtk_video_formats[] = { +static struct mtk_video_fmt mtk_video_formats[] = { { .fourcc =V4L2_PIX_FMT_H264 , .type =MTK_FMT_DEC ,
@@ -580,6 +580,16 @@ static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcodec_ctx *ctx)static void mtk_init_vdec_params (struct mtk_vcodec_ctx *ctx) { +unsigned int i; + +if (!(ctx->dev->dec_capability &VCODEC_CAPABILITY_4K_DISABLED )) { +for (i =0 ; i < num_supported_formats; i++) { + mtk_video_formats[i].frmsize.max_width = +VCODEC_DEC_4K_CODED_WIDTH ; + mtk_video_formats[i].frmsize.max_height = +VCODEC_DEC_4K_CODED_HEIGHT ; + } + } }static struct vb2_ops mtk_vdec_frame_vb2_ops = {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 276/694 media: mediatek: vcodec: Make MM21 the default capture format
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 6d020d81b91af80a977061e82de25cafa4456af5 ]
Given that only the MM21 capture format is supported by userspace tools (like gstreamer and libyuv), make it the default capture format.
This allows us to force the MM21 format even when a MM21 and MT21C capable firmware is available (which is needed while dynamic format switching isn't implemented in the driver), without causing the following regressions on v4l2-compliance:
fail: v4l2-test-formats.cpp(478): pixelformat 3132544d (MT21) for buftype 9 not reported by ENUM_FMT
test VIDIOC_G_FMT: FAIL
fail: v4l2-test-formats.cpp(478): pixelformat 3132544d (MT21) for buftype 9 not reported by ENUM_FMT
test VIDIOC_TRY_FMT: FAIL
fail: v4l2-test-formats.cpp(478): pixelformat 3132544d (MT21) for buftype 9 not reported by ENUM_FMT
test VIDIOC_S_FMT: FAIL
--- .../platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +4 -4
@@ -390,14 +390,14 @@ static void mtk_vcodec_get_supported_formats(struct mtk_vcodec_ctx *ctx)if (num_formats)return ; -if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_MM21 ) { -mtk_vcodec_add_formats (V4L2_PIX_FMT_MM21 , ctx); - cap_format_count++; - }if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_MT21C ) {mtk_vcodec_add_formats (V4L2_PIX_FMT_MT21C , ctx); cap_format_count++; } +if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_MM21 ) { +mtk_vcodec_add_formats (V4L2_PIX_FMT_MM21 , ctx); + cap_format_count++; + }if (ctx->dev->dec_capability &MTK_VDEC_FORMAT_H264_SLICE ) {mtk_vcodec_add_formats (V4L2_PIX_FMT_H264_SLICE , ctx); out_format_count++;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 277/694 media: mediatek: vcodec: Force capture queue format to MM21
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 68c7df527657a9e962da7b5b9c0308557357d8dc ]
While the decoder can produce frames in both MM21 and MT21C formats, only MM21 is currently supported by userspace tools (like gstreamer and libyuv). In order to ensure userspace keeps working after the SCP firmware is updated to support both MM21 and MT21C formats, force the MM21 format for the capture queue.
This is meant as a stopgap solution while dynamic format switching between MM21 and MT21C isn't implemented in the driver.
--- .../platform/mediatek/vcodec/mtk_vcodec_dec.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec.c +3 -21
@@ -39,10 +39,9 @@ static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_ctx *ctx, int format_index) {const struct mtk_vcodec_dec_pdata *dec_pdata = ctx->dev->vdec_pdata;const struct mtk_video_fmt *fmt; -struct mtk_q_data *q_data;int num_frame_count =0 , i; -bool ret = true; + fmt = &dec_pdata->vdec_formats[format_index];for (i =0 ; i < *dec_pdata->num_formats; i++) {if (dec_pdata->vdec_formats[i].type !=MTK_FMT_FRAME )continue ;
@@ -50,27 +49,10 @@ static bool mtk_vdec_get_cap_fmt(struct mtk_vcodec_ctx *ctx, int format_index) num_frame_count++; } -if (num_frame_count ==1 ) +if (num_frame_count ==1 || fmt->fourcc ==V4L2_PIX_FMT_MM21 )return true; - fmt = &dec_pdata->vdec_formats[format_index]; - q_data = &ctx->q_data[MTK_Q_DATA_SRC ]; -switch (q_data->fmt->fourcc) { -case V4L2_PIX_FMT_VP8_FRAME : -if (fmt->fourcc ==V4L2_PIX_FMT_MM21 ) - ret = true; -break ; -case V4L2_PIX_FMT_H264_SLICE : -case V4L2_PIX_FMT_VP9_FRAME : -if (fmt->fourcc ==V4L2_PIX_FMT_MM21 ) - ret = false; -break ; -default : - ret = true; -break ; - } - -return ret; +return false; } static struct mtk_q_data *mtk_vdec_get_q_data(struct mtk_vcodec_ctx *ctx,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 278/694 media: mediatek: vcodec: add params to record lat and core lat_buf count
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 5bbb6e2ca67477ab41163b32e6b3444faea74a5e ]
Using lat_buf to share decoder information between lat and core work queue, adding params to record the buf count.
--- .../platform/mediatek/vcodec/vdec_msg_queue.c | 23 ++++++++++++++++++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 6 +++++ 2 files changed, 28 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +22 -1
@@ -52,6 +52,22 @@ static struct list_head *vdec_get_buf_list(int hardware_index, struct vdec_lat_b } } +static void vdec_msg_queue_inc (struct vdec_msg_queue *msg_queue,int hardware_index) +{ +if (hardware_index ==MTK_VDEC_CORE ) +atomic_inc (&msg_queue->core_list_cnt); +else +atomic_inc (&msg_queue->lat_list_cnt); +} + +static void vdec_msg_queue_dec (struct vdec_msg_queue *msg_queue,int hardware_index) +{ +if (hardware_index ==MTK_VDEC_CORE ) +atomic_dec (&msg_queue->core_list_cnt); +else +atomic_dec (&msg_queue->lat_list_cnt); +} +int vdec_msg_queue_qbuf (struct vdec_msg_queue_ctx *msg_ctx,struct vdec_lat_buf *buf) {struct list_head *head;
@@ -66,6 +82,7 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buflist_add_tail (head, &msg_ctx->ready_queue); msg_ctx->ready_num++; +vdec_msg_queue_inc (&buf->ctx->msg_queue, msg_ctx->hardware_index);if (msg_ctx->hardware_index !=MTK_VDEC_CORE )wake_up_all (&msg_ctx->ready_to_use);else
@@ -127,6 +144,7 @@ struct vdec_lat_buf *vdec_msg_queue_dqbuf(struct vdec_msg_queue_ctx *msg_ctx)return NULL ; }list_del (head); +vdec_msg_queue_dec (&buf->ctx->msg_queue, msg_ctx->hardware_index); msg_ctx->ready_num--; mtk_v4l2_debug(3, "dqueue buf type:%d addr: 0x%p num: %d",
@@ -241,10 +259,13 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,vdec_msg_queue_init_ctx (&msg_queue->lat_ctx,MTK_VDEC_LAT0 );INIT_WORK (&msg_queue->core_work, vdec_msg_queue_core_work); + +atomic_set (&msg_queue->lat_list_cnt,0 ); +atomic_set (&msg_queue->core_list_cnt,0 ); + msg_queue->wdma_addr.size =vde_msg_queue_get_trans_size (ctx->picinfo.buf_w, ctx->picinfo.buf_h); - err =mtk_vcodec_mem_alloc (ctx, &msg_queue->wdma_addr);if (err) {mtk_v4l2_err ("failed to allocate wdma_addr buf" );
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +6 -0
@@ -72,6 +72,9 @@ struct vdec_lat_buf {* @wdma_wptr_addr: ube write point * @core_work: core hardware work * @lat_ctx: used to store lat buffer list +* +* @lat_list_cnt: used to record each instance lat list count +* @core_list_cnt: used to record each instance core list count */ struct vdec_msg_queue {struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT ];
@@ -82,6 +85,9 @@ struct vdec_msg_queue {struct work_struct core_work;struct vdec_msg_queue_ctx lat_ctx; + +atomic_t lat_list_cnt; +atomic_t core_list_cnt; };/**
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 279/694 media: mediatek: vcodec: using each instance lat_buf count replace core ready list
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit f7a3780cf96925670736582b9a623a2c9ffb4166 ]
Core Hardware decoder depends on each instance lat_buf count, calling queue_work decode again when the lat_buf count of each instance isn't zero.
--- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +1 -1
@@ -239,7 +239,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)mtk_vcodec_dec_disable_hardware (ctx,MTK_VDEC_CORE );vdec_msg_queue_qbuf (&ctx->msg_queue.lat_ctx, lat_buf); -if (!list_empty (&dev->msg_queue_core_ctx.ready_queue)) { +if (atomic_read (&lat_buf->ctx->msg_queue.core_list_cnt)) {mtk_v4l2_debug (3 ,"re-schedule to decode for core: %d" , dev->msg_queue_core_ctx.ready_num);queue_work (dev->core_workqueue, &msg_queue->core_work);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 280/694 media: mediatek: vcodec: move lat_buf to the top of core list
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 2cfca6c1bf8074175ea7a3b6b47f77ebdef8f701 ]
Current instance will decode done when begin to wait lat buf full, move the lat_buf of current instance to the top of core list to make sure current instance's lat_buf will be used firstly.
--- .../platform/mediatek/vcodec/vdec_msg_queue.c | 21 ++++++++++++++++++- .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +20 -1
@@ -174,8 +174,26 @@ void vdec_msg_queue_update_ube_wptr(struct vdec_msg_queue *msg_queue, uint64_t ubool vdec_msg_queue_wait_lat_buf_full (struct vdec_msg_queue *msg_queue) { +struct vdec_lat_buf *buf, *tmp; +struct list_head *list_core[3 ]; +struct vdec_msg_queue_ctx *core_ctx; +int ret, i, in_core_count =0 ;long timeout_jiff; -int ret; + + core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx; +spin_lock (&core_ctx->ready_lock); +list_for_each_entry_safe (buf, tmp, &core_ctx->ready_queue, core_list) { +if (buf && buf->ctx == msg_queue->ctx) { + list_core[in_core_count++] = &buf->core_list; +list_del (&buf->core_list); + } + } + +for (i =0 ; i < in_core_count; i++) { +list_add (list_core[in_core_count - (1 + i)], &core_ctx->ready_queue); +queue_work (msg_queue->ctx->dev->core_workqueue, &msg_queue->core_work); + } +spin_unlock (&core_ctx->ready_lock); timeout_jiff =msecs_to_jiffies (1000 * (NUM_BUFFER_COUNT +2 )); ret = wait_event_timeout(msg_queue->lat_ctx.ready_to_use,
@@ -257,6 +275,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,if (msg_queue->wdma_addr.size)return 0 ; + msg_queue->ctx = ctx;vdec_msg_queue_init_ctx (&msg_queue->lat_ctx,MTK_VDEC_LAT0 );INIT_WORK (&msg_queue->core_work, vdec_msg_queue_core_work);
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +2 -0
@@ -72,6 +72,7 @@ struct vdec_lat_buf {* @wdma_wptr_addr: ube write point * @core_work: core hardware work * @lat_ctx: used to store lat buffer list +* @ctx: point to mtk_vcodec_ctx * * @lat_list_cnt: used to record each instance lat list count * @core_list_cnt: used to record each instance core list count
@@ -85,6 +86,7 @@ struct vdec_msg_queue {struct work_struct core_work;struct vdec_msg_queue_ctx lat_ctx; +struct mtk_vcodec_ctx *ctx;atomic_t lat_list_cnt;atomic_t core_list_cnt;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 281/694 media: mediatek: vcodec: add core decode done event
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit d227af847ac2d7d90350124a1b2451e4fc1f050c ]
Need to make sure core decode done before current instance is free.
--- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c | 4 +++- drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +3 -1
@@ -196,7 +196,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)spin_unlock (&core_ctx->ready_lock); timeout_jiff =msecs_to_jiffies (1000 * (NUM_BUFFER_COUNT +2 )); - ret =wait_event_timeout (msg_queue->lat_ctx.ready_to_use, + ret =wait_event_timeout (msg_queue->ctx->msg_queue.core_dec_done, msg_queue->lat_ctx.ready_num ==NUM_BUFFER_COUNT , timeout_jiff);if (ret) {
@@ -257,6 +257,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)mtk_vcodec_dec_disable_hardware (ctx,MTK_VDEC_CORE );vdec_msg_queue_qbuf (&ctx->msg_queue.lat_ctx, lat_buf); +wake_up_all (&ctx->msg_queue.core_dec_done);if (atomic_read (&lat_buf->ctx->msg_queue.core_list_cnt)) {mtk_v4l2_debug (3 ,"re-schedule to decode for core: %d" , dev->msg_queue_core_ctx.ready_num);
@@ -281,6 +282,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,atomic_set (&msg_queue->lat_list_cnt,0 );atomic_set (&msg_queue->core_list_cnt,0 ); +init_waitqueue_head (&msg_queue->core_dec_done); msg_queue->wdma_addr.size = vde_msg_queue_get_trans_size(ctx->picinfo.buf_w,
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +2 -0
@@ -76,6 +76,7 @@ struct vdec_lat_buf {* * @lat_list_cnt: used to record each instance lat list count * @core_list_cnt: used to record each instance core list count +* @core_dec_done: core work queue decode done event */ struct vdec_msg_queue {struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT ];
@@ -90,6 +91,7 @@ struct vdec_msg_queue {atomic_t lat_list_cnt;atomic_t core_list_cnt; +wait_queue_head_t core_dec_done; };/**
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 282/694 media: mediatek: vcodec: remove unused lat_buf
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit af50b13dd3d7d5dbc1f08add1c462398e926a053 ]
Remove unused lat_buf from core list, or leading to core list access NULL point.
--- .../platform/mediatek/vcodec/vdec_msg_queue.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +15 -3
@@ -177,7 +177,7 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue)struct vdec_lat_buf *buf, *tmp;struct list_head *list_core[3 ];struct vdec_msg_queue_ctx *core_ctx; -int ret, i, in_core_count =0 ; +int ret, i, in_core_count =0 , count =0 ;long timeout_jiff; core_ctx = &msg_queue->ctx->dev->msg_queue_core_ctx;
@@ -204,8 +204,20 @@ bool vdec_msg_queue_wait_lat_buf_full(struct vdec_msg_queue *msg_queue) msg_queue->lat_ctx.ready_num);return true; } -mtk_v4l2_err ("failed with lat buf isn't full: %d" , - msg_queue->lat_ctx.ready_num); + +spin_lock (&core_ctx->ready_lock); +list_for_each_entry_safe (buf, tmp, &core_ctx->ready_queue, core_list) { +if (buf && buf->ctx == msg_queue->ctx) { + count++; +list_del (&buf->core_list); + } + } +spin_unlock (&core_ctx->ready_lock); + +mtk_v4l2_err ("failed with lat buf isn't full: list(%d %d) count:%d" , +atomic_read (&msg_queue->lat_list_cnt), +atomic_read (&msg_queue->core_list_cnt), count); +return false; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 283/694 media: mediatek: vcodec: making sure queue_work successfully
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 2e0ef56d81cb2569624d288b7e95a8a2734a7c74 ]
Putting core work to work queue using queue_work maybe fail, call queue_work again when the count of core work in work queue is less than core_list_cnt, making sure all the buffer in core list can be scheduled.
--- .../platform/mediatek/vcodec/vdec_msg_queue.c | 31 ++++++++++++++----- .../platform/mediatek/vcodec/vdec_msg_queue.h | 2 ++ 2 files changed, 25 insertions(+), 8 deletions(-)
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +23 -8
@@ -71,6 +71,7 @@ static void vdec_msg_queue_dec(struct vdec_msg_queue *msg_queue, int hardware_inint vdec_msg_queue_qbuf (struct vdec_msg_queue_ctx *msg_ctx,struct vdec_lat_buf *buf) {struct list_head *head; +int status; head =vdec_get_buf_list (msg_ctx->hardware_index, buf);if (!head) {
@@ -83,11 +84,17 @@ int vdec_msg_queue_qbuf(struct vdec_msg_queue_ctx *msg_ctx, struct vdec_lat_buf msg_ctx->ready_num++;vdec_msg_queue_inc (&buf->ctx->msg_queue, msg_ctx->hardware_index); -if (msg_ctx->hardware_index !=MTK_VDEC_CORE ) +if (msg_ctx->hardware_index !=MTK_VDEC_CORE ) {wake_up_all (&msg_ctx->ready_to_use); -else -queue_work (buf->ctx->dev->core_workqueue, - &buf->ctx->msg_queue.core_work); + }else { +if (buf->ctx->msg_queue.core_work_cnt < +atomic_read (&buf->ctx->msg_queue.core_list_cnt)) { + status =queue_work (buf->ctx->dev->core_workqueue, + &buf->ctx->msg_queue.core_work); +if (status) + buf->ctx->msg_queue.core_work_cnt++; + } + }mtk_v4l2_debug (3 ,"enqueue buf type: %d addr: 0x%p num: %d" , msg_ctx->hardware_index, buf, msg_ctx->ready_num);
@@ -254,6 +261,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work) container_of(msg_queue, struct mtk_vcodec_ctx, msg_queue);struct mtk_vcodec_dev *dev = ctx->dev;struct vdec_lat_buf *lat_buf; +int status; lat_buf =vdec_msg_queue_dqbuf (&dev->msg_queue_core_ctx);if (!lat_buf)
@@ -270,11 +278,17 @@ static void vdec_msg_queue_core_work(struct work_struct *work)vdec_msg_queue_qbuf (&ctx->msg_queue.lat_ctx, lat_buf);wake_up_all (&ctx->msg_queue.core_dec_done); -if (atomic_read (&lat_buf->ctx->msg_queue.core_list_cnt)) { -mtk_v4l2_debug (3 ,"re-schedule to decode for core: %d" , - dev->msg_queue_core_ctx.ready_num); -queue_work (dev->core_workqueue, &msg_queue->core_work); +spin_lock (&dev->msg_queue_core_ctx.ready_lock); + lat_buf->ctx->msg_queue.core_work_cnt--; + +if (lat_buf->ctx->msg_queue.core_work_cnt < +atomic_read (&lat_buf->ctx->msg_queue.core_list_cnt)) { + status =queue_work (lat_buf->ctx->dev->core_workqueue, + &lat_buf->ctx->msg_queue.core_work); +if (status) + lat_buf->ctx->msg_queue.core_work_cnt++; } +spin_unlock (&dev->msg_queue_core_ctx.ready_lock); } int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,
@@ -289,6 +303,7 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue,return 0 ; msg_queue->ctx = ctx; + msg_queue->core_work_cnt =0 ;vdec_msg_queue_init_ctx (&msg_queue->lat_ctx,MTK_VDEC_LAT0 );INIT_WORK (&msg_queue->core_work, vdec_msg_queue_core_work);
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +2 -0
@@ -77,6 +77,7 @@ struct vdec_lat_buf {* @lat_list_cnt: used to record each instance lat list count * @core_list_cnt: used to record each instance core list count * @core_dec_done: core work queue decode done event +* @core_work_cnt: the number of core work in work queue */ struct vdec_msg_queue {struct vdec_lat_buf lat_buf[NUM_BUFFER_COUNT ];
@@ -92,6 +93,7 @@ struct vdec_msg_queue {atomic_t lat_list_cnt;atomic_t core_list_cnt;wait_queue_head_t core_dec_done; +int core_work_cnt; };/**
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 284/694 media: mediatek: vcodec: change lat thread decode error condition
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 960badda95f10fb0c60f6f64978b19eafa9507a7 ]
If lat thread can't get lat buffer, it should be that current instance don't be schedulded, the driver can't free the src buffer directly.
--- .../platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c | 6 ++++-- .../platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c | 2 +- .../platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +4 -2
@@ -258,8 +258,10 @@ static void mtk_vdec_worker(struct work_struct *work)if (src_buf_req)v4l2_ctrl_request_complete (src_buf_req, &ctx->ctrl_hdl); }else { -v4l2_m2m_src_buf_remove (ctx->m2m_ctx); -v4l2_m2m_buf_done (vb2_v4l2_src, state); +if (ret != -EAGAIN ) { +v4l2_m2m_src_buf_remove (ctx->m2m_ctx); +v4l2_m2m_buf_done (vb2_v4l2_src, state); + }v4l2_m2m_job_finish (dev->m2m_dev_dec, ctx->m2m_ctx); } }
drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c +1 -1
@@ -597,7 +597,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, lat_buf =vdec_msg_queue_dqbuf (&inst->ctx->msg_queue.lat_ctx);if (!lat_buf) {mtk_vcodec_err (inst,"failed to get lat buffer" ); -return -EINVAL ; +return -EAGAIN ; } share_info = lat_buf->private_data; src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer);
drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c +1 -1
@@ -2070,7 +2070,7 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, lat_buf =vdec_msg_queue_dqbuf (&instance->ctx->msg_queue.lat_ctx);if (!lat_buf) {mtk_vcodec_err (instance,"Failed to get VP9 lat buf\n" ); -return -EBUSY ; +return -EAGAIN ; } pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data;if (!pfc) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 285/694 media: cedrus: fix use after free bug in cedrus_remove due to race condition
In reply to Greg Kroah-HartmanFrom: Zheng Wang <[email protected]>
[ Upstream commit 50d0a7aea4809cef87979d4669911276aa23b71f ]
In cedrus_probe, dev->watchdog_work is bound with cedrus_watchdog function. In cedrus_device_run, it will started by schedule_delayed_work. If there is an unfinished work in cedrus_remove, there may be a race condition and trigger UAF bug.
CPU0 CPU1
|cedrus_watchdog
cedrus_remove |
v4l2_m2m_release |
kfree(m2m_dev) |
|
| v4l2_m2m_get_curr_priv
| m2m_dev //useFix it by canceling the worker in cedrus_remove.
--- drivers/staging/media/sunxi/cedrus/cedrus.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/media/sunxi/cedrus/cedrus.c +1 -0
@@ -547,6 +547,7 @@ static int cedrus_remove(struct platform_device *pdev) {struct cedrus_dev *dev =platform_get_drvdata (pdev); +cancel_delayed_work_sync (&dev->watchdog_work);if (media_devnode_is_registered (dev->mdev.devnode)) {media_device_unregister (&dev->mdev);v4l2_m2m_unregister_media_controller (dev->m2m_dev);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 286/694 media: rkvdec: fix use after free bug in rkvdec_remove
In reply to Greg Kroah-HartmanFrom: Zheng Wang <[email protected]>
[ Upstream commit 3228cec23b8b29215e18090c6ba635840190993d ]
In rkvdec_probe, rkvdec->watchdog_work is bound with rkvdec_watchdog_func. Then rkvdec_vp9_run may be called to start the work.
If we remove the module which will call rkvdec_remove
to make cleanup, there may be a unfinished work. The possible sequence is as follows, which will cause a typical UAF bug.
Fix it by canceling the work before cleanup in rkvdec_remove.
CPU0 CPU1
|rkvdec_watchdog_func
rkvdec_remove |
rkvdec_v4l2_cleanup|
v4l2_m2m_release |
kfree(m2m_dev); |
|
| v4l2_m2m_get_curr_priv
| m2m_dev->curr_ctx //use--- drivers/staging/media/rkvdec/rkvdec.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/staging/media/rkvdec/rkvdec.c +2 -0
@@ -1066,6 +1066,8 @@ static int rkvdec_remove(struct platform_device *pdev) {struct rkvdec_dev *rkvdec =platform_get_drvdata (pdev); +cancel_delayed_work_sync (&rkvdec->watchdog_work); +rkvdec_v4l2_cleanup (rkvdec);pm_runtime_disable (&pdev->dev);pm_runtime_dont_use_autosuspend (&pdev->dev);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 287/694 platform/x86/amd/pmf: Move out of BIOS SMN pair for driver probe
In reply to Greg Kroah-HartmanFrom: Shyam Sundar S K <[email protected]>
[ Upstream commit aec8298c093f052fc8a86f9411b69b23953b0edb ]
The current SMN index used for the driver probe seems to be meant for the BIOS pair and there are potential concurrency problems that can occur with an inopportune SMI.
It is been advised to use SMN_INDEX_0 instead of SMN_INDEX_2, which is what amd_nb.c provides and this function has protections to ensure that only one caller can use it at a time.
--- drivers/platform/x86/amd/pmf/Kconfig | 1 + drivers/platform/x86/amd/pmf/core.c | 22 +++++----------------- 2 files changed, 6 insertions(+), 17 deletions(-)
drivers/platform/x86/amd/pmf/Kconfig +1 -0
@@ -7,6 +7,7 @@ config AMD_PMF tristate "AMD Platform Management Framework" depends on ACPI && PCI depends on POWER_SUPPLY + depends on AMD_NB select ACPI_PLATFORM_PROFILE help This driver provides support for the AMD Platform Management Framework.
drivers/platform/x86/amd/pmf/core.c +5 -17
@@ -8,6 +8,7 @@* Author: Shyam Sundar S K <[email protected]> */ +#include <asm/amd_nb.h> #include <linux/debugfs.h> #include <linux/iopoll.h> #include <linux/module.h>
@@ -22,8 +23,6 @@#define AMD_PMF_REGISTER_ARGUMENT 0xA58/* Base address of SMU for mapping physical address to virtual address */ -#define AMD_PMF_SMU_INDEX_ADDRESS 0xB8 -#define AMD_PMF_SMU_INDEX_DATA 0xBC#define AMD_PMF_MAPPING_SIZE 0x01000#define AMD_PMF_BASE_ADDR_OFFSET 0x10000#define AMD_PMF_BASE_ADDR_LO 0x13B102E8
@@ -348,30 +347,19 @@ static int amd_pmf_probe(struct platform_device *pdev) } dev->cpu_id = rdev->device; - err =pci_write_config_dword (rdev,AMD_PMF_SMU_INDEX_ADDRESS ,AMD_PMF_BASE_ADDR_LO ); -if (err) { -dev_err (dev->dev,"error writing to 0x%x\n" ,AMD_PMF_SMU_INDEX_ADDRESS ); -pci_dev_put (rdev); -return pcibios_err_to_errno (err); - } - err =pci_read_config_dword (rdev,AMD_PMF_SMU_INDEX_DATA , &val); + err =amd_smn_read (0 ,AMD_PMF_BASE_ADDR_LO , &val);if (err) { +dev_err (dev->dev,"error in reading from 0x%x\n" ,AMD_PMF_BASE_ADDR_LO );pci_dev_put (rdev);return pcibios_err_to_errno (err); } base_addr_lo = val &AMD_PMF_BASE_ADDR_HI_MASK ; - err =pci_write_config_dword (rdev,AMD_PMF_SMU_INDEX_ADDRESS ,AMD_PMF_BASE_ADDR_HI ); -if (err) { -dev_err (dev->dev,"error writing to 0x%x\n" ,AMD_PMF_SMU_INDEX_ADDRESS ); -pci_dev_put (rdev); -return pcibios_err_to_errno (err); - } - - err =pci_read_config_dword (rdev,AMD_PMF_SMU_INDEX_DATA , &val); + err =amd_smn_read (0 ,AMD_PMF_BASE_ADDR_HI , &val);if (err) { +dev_err (dev->dev,"error in reading from 0x%x\n" ,AMD_PMF_BASE_ADDR_HI );pci_dev_put (rdev);return pcibios_err_to_errno (err); }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 288/694 platform/x86/amd: pmc: Dont try to read SMU version on Picasso
In reply to Greg Kroah-HartmanFrom: Mario Limonciello <[email protected]>
[ Upstream commit b845772677ea19b8e4c032bc07393ef32de4ee39 ]
Picasso doesn't support the command in the uPEP mailbox to try to read the SMU version.
--- drivers/platform/x86/amd/pmc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/x86/amd/pmc.c +3 -0
@@ -403,6 +403,9 @@ static int amd_pmc_get_smu_version(struct amd_pmc_dev *dev)int rc;u32 val; +if (dev->cpu_id ==AMD_CPU_ID_PCO ) +return -ENODEV ; + rc =amd_pmc_send_cmd (dev,0 , &val,SMU_MSG_GETSMUVERSION ,1 );if (rc)return rc;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 289/694 platform/x86/amd: pmc: Hide SMU version and program attributes for Picasso
In reply to Greg Kroah-HartmanFrom: Mario Limonciello <[email protected]>
[ Upstream commit 5ec9ee0d464750d72972d5685edf675824e259a1 ]
As the command to get version isn't supported on Picasso, we shouldn't be exposing this into sysfs either.
--- drivers/platform/x86/amd/pmc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/pmc.c +20 -1
@@ -452,12 +452,31 @@ static ssize_t smu_program_show(struct device *d, struct device_attribute *attr,static DEVICE_ATTR_RO (smu_fw_version);static DEVICE_ATTR_RO (smu_program); +static umode_t pmc_attr_is_visible (struct kobject *kobj,struct attribute *attr,int idx) +{ +struct device *dev =kobj_to_dev (kobj); +struct amd_pmc_dev *pdev =dev_get_drvdata (dev); + +if (pdev->cpu_id ==AMD_CPU_ID_PCO ) +return 0 ; +return 0444 ; +} +static struct attribute *pmc_attrs[] = { &dev_attr_smu_fw_version.attr, &dev_attr_smu_program.attr,NULL , }; -ATTRIBUTE_GROUPS (pmc); + +static struct attribute_group pmc_attr_group = { + .attrs = pmc_attrs, + .is_visible = pmc_attr_is_visible, +}; + +static const struct attribute_group *pmc_groups[] = { + &pmc_attr_group, +NULL , +};static int smu_fw_info_show (struct seq_file *s,void *unused) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 290/694 platform/x86/amd: pmc: Dont dump data after resume from s0i3 on picasso
In reply to Greg Kroah-HartmanFrom: Mario Limonciello <[email protected]>
[ Upstream commit 7abc3618b65304d409d9489d77e4a8f047842fb7 ]
This command isn't supported on Picasso, so guard against running it to avoid errors like SMU cmd unknown. err: 0xfe in the logs.
--- drivers/platform/x86/amd/pmc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/platform/x86/amd/pmc.c +9 -1
@@ -834,6 +834,14 @@ static void amd_pmc_s2idle_check(void)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); } +static int amd_pmc_dump_data (struct amd_pmc_dev *pdev) +{ +if (pdev->cpu_id ==AMD_CPU_ID_PCO ) +return -ENODEV ; + +return amd_pmc_send_cmd (pdev,0 ,NULL ,SMU_MSG_LOG_DUMP_DATA ,0 ); +} +static void amd_pmc_s2idle_restore (void ) {struct amd_pmc_dev *pdev = &pmc;
@@ -846,7 +854,7 @@ static void amd_pmc_s2idle_restore(void)dev_err (pdev->dev,"resume failed: %d\n" , rc);/* Let SMU know that we are looking for stats */ -amd_pmc_send_cmd (pdev,0 ,NULL ,SMU_MSG_LOG_DUMP_DATA ,0 ); +amd_pmc_dump_data (pdev); rc =amd_pmc_write_stb (pdev,AMD_PMC_STB_S2IDLE_RESTORE );if (rc)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 291/694 platform/x86/amd: pmc: Move idlemask check into `amd_pmc_idlemask_read`
In reply to Greg Kroah-HartmanFrom: Mario Limonciello <[email protected]>
[ Upstream commit 9217bd1d7699f34a01b26ba14ff38c1714ce1185 ]
The version check requirement for idle mask support actually only applies to RN/CZN/BRC platforms.
So far no issues have happened because the PMFW version string is bigger on other supported systems. This can be reset for any new platform so move the check to only RN/CZN/BRC case.
--- drivers/platform/x86/amd/pmc.c | 74 +++++++++++++++------------------- 1 file changed, 33 insertions(+), 41 deletions(-)
drivers/platform/x86/amd/pmc.c +33 -41
@@ -342,33 +342,6 @@ static int amd_pmc_setup_smu_logging(struct amd_pmc_dev *dev)return 0 ; } -static int amd_pmc_idlemask_read (struct amd_pmc_dev *pdev,struct device *dev, -struct seq_file *s) -{ -u32 val; - -switch (pdev->cpu_id) { -case AMD_CPU_ID_CZN : - val =amd_pmc_reg_read (pdev,AMD_PMC_SCRATCH_REG_CZN ); -break ; -case AMD_CPU_ID_YC : -case AMD_CPU_ID_CB : -case AMD_CPU_ID_PS : - val =amd_pmc_reg_read (pdev,AMD_PMC_SCRATCH_REG_YC ); -break ; -default : -return -EINVAL ; - } - -if (dev) -dev_dbg (pdev->dev,"SMU idlemask s0i3: 0x%x\n" , val); - -if (s) -seq_printf (s,"SMU idlemask : 0x%x\n" , val); - -return 0 ; -} -static int get_metrics_table (struct amd_pmc_dev *pdev,struct smu_metrics *table) {if (!pdev->smu_virt_addr) {
@@ -543,28 +516,47 @@ static int s0ix_stats_show(struct seq_file *s, void *unused) }DEFINE_SHOW_ATTRIBUTE (s0ix_stats); -static int amd_pmc_idlemask_show (struct seq_file *s,void *unused) +static int amd_pmc_idlemask_read (struct amd_pmc_dev *pdev,struct device *dev, +struct seq_file *s) { -struct amd_pmc_dev *dev = s->private; +u32 val;int rc; -/* we haven't yet read SMU version */ -if (!dev->major) { - rc =amd_pmc_get_smu_version (dev); -if (rc) -return rc; +switch (pdev->cpu_id) { +case AMD_CPU_ID_CZN : +/* we haven't yet read SMU version */ +if (!pdev->major) { + rc =amd_pmc_get_smu_version (pdev); +if (rc) +return rc; + } +if (pdev->major >56 || (pdev->major >=55 && pdev->minor >=37 )) + val =amd_pmc_reg_read (pdev,AMD_PMC_SCRATCH_REG_CZN ); +else +return -EINVAL ; +break ; +case AMD_CPU_ID_YC : +case AMD_CPU_ID_CB : +case AMD_CPU_ID_PS : + val =amd_pmc_reg_read (pdev,AMD_PMC_SCRATCH_REG_YC ); +break ; +default : +return -EINVAL ; } -if (dev->major >56 || (dev->major >=55 && dev->minor >=37 )) { - rc =amd_pmc_idlemask_read (dev,NULL , s); -if (rc) -return rc; - }else { -seq_puts (s,"Unsupported SMU version for Idlemask\n" ); - } +if (dev) +dev_dbg (pdev->dev,"SMU idlemask s0i3: 0x%x\n" , val); + +if (s) +seq_printf (s,"SMU idlemask : 0x%x\n" , val);return 0 ; } + +static int amd_pmc_idlemask_show (struct seq_file *s,void *unused) +{ +return amd_pmc_idlemask_read (s->private,NULL , s); +}DEFINE_SHOW_ATTRIBUTE (amd_pmc_idlemask);static void amd_pmc_dbgfs_unregister (struct amd_pmc_dev *dev)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 292/694 platform/x86/amd: pmc: Utilize SMN index 0 for driver probe
In reply to Greg Kroah-HartmanFrom: Shyam Sundar S K <[email protected]>
[ Upstream commit 310e782a99c7f16fb533a45d8f9c16defefa5aab ]
The current SMN index used for the driver probe seems to be meant for the BIOS pair and there are potential concurrency problems that can occur with an inopportune SMI.
It is been advised to use SMN_INDEX_0 instead of SMN_INDEX_2, which is what amd_nb.c provides and this function has protections to ensure that only one caller can use it at a time.
--- drivers/platform/x86/amd/Kconfig | 2 +- drivers/platform/x86/amd/pmc.c | 23 +++++------------------ 2 files changed, 6 insertions(+), 19 deletions(-)
drivers/platform/x86/amd/Kconfig +1 -1
@@ -7,7 +7,7 @@ source "drivers/platform/x86/amd/pmf/Kconfig" config AMD_PMC tristate "AMD SoC PMC driver" - depends on ACPI && PCI && RTC_CLASS + depends on ACPI && PCI && RTC_CLASS && AMD_NB select SERIO help The driver provides support for AMD Power Management Controller
drivers/platform/x86/amd/pmc.c +5 -18
@@ -10,6 +10,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <asm/amd_nb.h> #include <linux/acpi.h> #include <linux/bitfield.h> #include <linux/bits.h>
@@ -56,8 +57,6 @@#define S2D_TELEMETRY_DRAMBYTES_MAX 0x1000000/* Base address of SMU for mapping physical address to virtual address */ -#define AMD_PMC_SMU_INDEX_ADDRESS 0xB8 -#define AMD_PMC_SMU_INDEX_DATA 0xBC#define AMD_PMC_MAPPING_SIZE 0x01000#define AMD_PMC_BASE_ADDR_OFFSET 0x10000#define AMD_PMC_BASE_ADDR_LO 0x13B102E8
@@ -983,30 +982,18 @@ static int amd_pmc_probe(struct platform_device *pdev) dev->cpu_id = rdev->device; dev->rdev = rdev; - err =pci_write_config_dword (rdev,AMD_PMC_SMU_INDEX_ADDRESS ,AMD_PMC_BASE_ADDR_LO ); -if (err) { -dev_err (dev->dev,"error writing to 0x%x\n" ,AMD_PMC_SMU_INDEX_ADDRESS ); - err =pcibios_err_to_errno (err); - goto err_pci_dev_put; - } - - err =pci_read_config_dword (rdev,AMD_PMC_SMU_INDEX_DATA , &val); + err =amd_smn_read (0 ,AMD_PMC_BASE_ADDR_LO , &val);if (err) { +dev_err (dev->dev,"error reading 0x%x\n" ,AMD_PMC_BASE_ADDR_LO ); err =pcibios_err_to_errno (err); goto err_pci_dev_put; } base_addr_lo = val &AMD_PMC_BASE_ADDR_HI_MASK ; - err =pci_write_config_dword (rdev,AMD_PMC_SMU_INDEX_ADDRESS ,AMD_PMC_BASE_ADDR_HI ); -if (err) { -dev_err (dev->dev,"error writing to 0x%x\n" ,AMD_PMC_SMU_INDEX_ADDRESS ); - err =pcibios_err_to_errno (err); - goto err_pci_dev_put; - } - - err =pci_read_config_dword (rdev,AMD_PMC_SMU_INDEX_DATA , &val); + err =amd_smn_read (0 ,AMD_PMC_BASE_ADDR_HI , &val);if (err) { +dev_err (dev->dev,"error reading 0x%x\n" ,AMD_PMC_BASE_ADDR_HI ); err =pcibios_err_to_errno (err); goto err_pci_dev_put; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 293/694 platform/x86/amd: pmc: Move out of BIOS SMN pair for STB init
In reply to Greg Kroah-HartmanFrom: Shyam Sundar S K <[email protected]>
[ Upstream commit 8d99129eef8f42377b41c1bacee9f8ce806e9f44 ]
The current SMN index used for the driver probe seems to be meant for the BIOS pair and there are potential concurrency problems that can occur with an inopportune SMI.
It is been advised to use SMN_INDEX_0 instead of SMN_INDEX_6, which is what amd_nb.c provides and this function has protections to ensure that only one caller can use it at a time.
--- drivers/platform/x86/amd/pmc.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/platform/x86/amd/pmc.c +4 -22
@@ -38,8 +38,6 @@#define AMD_PMC_SCRATCH_REG_YC 0xD14/* STB Registers */ -#define AMD_PMC_STB_INDEX_ADDRESS 0xF8 -#define AMD_PMC_STB_INDEX_DATA 0xFC#define AMD_PMC_STB_PMI_0 0x03E30600#define AMD_PMC_STB_S2IDLE_PREPARE 0xC6000001#define AMD_PMC_STB_S2IDLE_RESTORE 0xC6000002
@@ -923,17 +921,9 @@ static int amd_pmc_write_stb(struct amd_pmc_dev *dev, u32 data) {int err; - err =pci_write_config_dword (dev->rdev,AMD_PMC_STB_INDEX_ADDRESS ,AMD_PMC_STB_PMI_0 ); + err =amd_smn_write (0 ,AMD_PMC_STB_PMI_0 , data);if (err) { -dev_err (dev->dev,"failed to write addr in stb: 0x%X\n" , -AMD_PMC_STB_INDEX_ADDRESS ); -return pcibios_err_to_errno (err); - } - - err =pci_write_config_dword (dev->rdev,AMD_PMC_STB_INDEX_DATA , data); -if (err) { -dev_err (dev->dev,"failed to write data in stb: 0x%X\n" , -AMD_PMC_STB_INDEX_DATA ); +dev_err (dev->dev,"failed to write data in stb: 0x%X\n" ,AMD_PMC_STB_PMI_0 );return pcibios_err_to_errno (err); }
@@ -944,18 +934,10 @@ static int amd_pmc_read_stb(struct amd_pmc_dev *dev, u32 *buf) {int i, err; - err =pci_write_config_dword (dev->rdev,AMD_PMC_STB_INDEX_ADDRESS ,AMD_PMC_STB_PMI_0 ); -if (err) { -dev_err (dev->dev,"error writing addr to stb: 0x%X\n" , -AMD_PMC_STB_INDEX_ADDRESS ); -return pcibios_err_to_errno (err); - } -for (i =0 ; i <FIFO_SIZE ; i++) { - err =pci_read_config_dword (dev->rdev,AMD_PMC_STB_INDEX_DATA , buf++); + err =amd_smn_read (0 ,AMD_PMC_STB_PMI_0 , buf++);if (err) { -dev_err (dev->dev,"error reading data from stb: 0x%X\n" , -AMD_PMC_STB_INDEX_DATA ); +dev_err (dev->dev,"error reading data from stb: 0x%X\n" ,AMD_PMC_STB_PMI_0 );return pcibios_err_to_errno (err); } }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 294/694 media: dm1105: Fix use after free bug in dm1105_remove due to race condition
In reply to Greg Kroah-HartmanFrom: Zheng Wang <[email protected]>
[ Upstream commit 5abda7a16698d4d1f47af1168d8fa2c640116b4a ]
In dm1105_probe, it called dm1105_ir_init and bound &dm1105->ir.work with dm1105_emit_key.
When it handles IRQ request with dm1105_irq, it may call schedule_work to start the work.
When we call dm1105_remove to remove the driver, there may be a sequence as follows:
Fix it by finishing the work before cleanup in dm1105_remove
CPU0 CPU1
|dm1105_emit_key
dm1105_remove |
dm1105_ir_exit |
rc_unregister_device |
rc_free_device |
rc_dev_release |
kfree(dev); |
|
| rc_keydown
| //use--- drivers/media/pci/dm1105/dm1105.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/pci/dm1105/dm1105.c +1 -0
@@ -1176,6 +1176,7 @@ static void dm1105_remove(struct pci_dev *pdev)struct dvb_demux *dvbdemux = &dev->demux;struct dmx_demux *dmx = &dvbdemux->dmx; +cancel_work_sync (&dev->ir.work);dm1105_ir_exit (dev); dmx->close (dmx);dvb_net_release (&dev->dvbnet);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 295/694 media: saa7134: fix use after free bug in saa7134_finidev due to race condition
In reply to Greg Kroah-HartmanFrom: Zheng Wang <[email protected]>
[ Upstream commit 30cf57da176cca80f11df0d9b7f71581fe601389 ]
In saa7134_initdev, it will call saa7134_hwinit1. There are three function invoking here: saa7134_video_init1, saa7134_ts_init1 and saa7134_vbi_init1.
All of them will init a timer with same function. Take saa7134_video_init1 as an example. It'll bound &dev->video_q.timeout with saa7134_buffer_timeout.
In buffer_activate, the timer funtcion is started.
If we remove the module or device which will call saa7134_finidev to make cleanup, there may be a unfinished work. The possible sequence is as follows, which will cause a typical UAF bug.
Fix it by canceling the timer works accordingly before cleanup in saa7134_finidev.
CPU0 CPU1
|saa7134_buffer_timeout
saa7134_finidev |
kfree(dev); |
|
| saa7134_buffer_next
| //use dev--- drivers/media/pci/saa7134/saa7134-ts.c | 1 + drivers/media/pci/saa7134/saa7134-vbi.c | 1 + drivers/media/pci/saa7134/saa7134-video.c | 1 + 3 files changed, 3 insertions(+)
drivers/media/pci/saa7134/saa7134-ts.c +1 -0
@@ -300,6 +300,7 @@ int saa7134_ts_start(struct saa7134_dev *dev)int saa7134_ts_fini (struct saa7134_dev *dev) { +del_timer_sync (&dev->ts_q.timeout);saa7134_pgtable_free (dev->pci, &dev->ts_q.pt);return 0 ; }
drivers/media/pci/saa7134/saa7134-vbi.c +1 -0
@@ -185,6 +185,7 @@ int saa7134_vbi_init1(struct saa7134_dev *dev)int saa7134_vbi_fini (struct saa7134_dev *dev) {/* nothing */ +del_timer_sync (&dev->vbi_q.timeout);return 0 ; }
drivers/media/pci/saa7134/saa7134-video.c +1 -0
@@ -2146,6 +2146,7 @@ int saa7134_video_init1(struct saa7134_dev *dev)void saa7134_video_fini (struct saa7134_dev *dev) { +del_timer_sync (&dev->video_q.timeout);/* free stuff */ saa7134_pgtable_free (dev->pci, &dev->video_q.pt);saa7134_pgtable_free (dev->pci, &dev->vbi_q.pt);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 296/694 media: platform: mtk-mdp3: fix potential frame size overflow in mdp_try_fmt_mplane()
In reply to Greg Kroah-HartmanFrom: Moudy Ho <[email protected]>
[ Upstream commit 4168720753ce6c14c5d3a35302fc2e1841383443 ]
Fix overflow risk when setting certain formats whose frame size exceeds a RGB24 with 7723x7723 resolution.
For example, a 7723x7724 RGB24 frame:
1. bpl (byte per line) = 7723 * 3.
2. Overflow occurs when bpl * 7724 * depth.
--- drivers/media/platform/mediatek/mdp3/mtk-mdp3-regs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/media/platform/mediatek/mdp3/mtk-mdp3-regs.c +6 -4
@@ -4,6 +4,7 @@* Author: Ping-Hsun Wu <[email protected]> */ +#include <linux/math64.h> #include <media/v4l2-common.h> #include <media/videobuf2-v4l2.h> #include <media/videobuf2-dma-contig.h>
@@ -428,14 +429,15 @@ const struct mdp_format *mdp_try_fmt_mplane(struct v4l2_format *f,u32 bpl = pix_mp->plane_fmt[i].bytesperline;u32 min_si, max_si;u32 si = pix_mp->plane_fmt[i].sizeimage; +u64 di; bpl =clamp (bpl, min_bpl, max_bpl); pix_mp->plane_fmt[i].bytesperline = bpl; - min_si = (bpl * pix_mp->height * fmt->depth[i]) / - fmt->row_depth[i]; - max_si = (bpl * s.max_height * fmt->depth[i]) / - fmt->row_depth[i]; + di = (u64 )bpl * pix_mp->height * fmt->depth[i]; + min_si = (u32 )div_u64 (di, fmt->row_depth[i]); + di = (u64 )bpl * s.max_height * fmt->depth[i]; + max_si = (u32 )div_u64 (di, fmt->row_depth[i]); si =clamp (si, min_si, max_si); pix_mp->plane_fmt[i].sizeimage = si;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 297/694 media: vsp1: Replace vb2_is_streaming() with vb2_start_streaming_called()
In reply to Greg Kroah-HartmanFrom: Laurent Pinchart <[email protected]>
[ Upstream commit 52d8caca3d533cc499f1255be25576ffd936ec95 ]
The vsp1 driver uses the vb2_is_streaming() function in its .buf_queue() handler to check if the .start_streaming() operation has been called, and decide whether to just add the buffer to an internal queue, or also trigger a hardware run. vb2_is_streaming() relies on the vb2_queue structure's streaming field, which used to be set only after calling the .start_streaming() operation.
Commit a10b21532574 ("media: vb2: add (un)prepare_streaming queue ops") changed this, setting the .streaming field in vb2_core_streamon() before enqueuing buffers to the driver and calling .start_streaming(). This broke the vsp1 driver which now believes that .start_streaming() has been called when it hasn't, leading to a crash:
[ 881.058705] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 [ 881.067495] Mem abort info: [ 881.070290] ESR = 0x0000000096000006 [ 881.074042] EC = 0x25: DABT (current EL), IL = 32 bits [ 881.079358] SET = 0, FnV = 0 [ 881.082414] EA = 0, S1PTW = 0 [ 881.085558] FSC = 0x06: level 2 translation fault [ 881.090439] Data abort info: [ 881.093320] ISV = 0, ISS = 0x00000006 [ 881.097157] CM = 0, WnR = 0 [ 881.100126] user pgtable: 4k pages, 48-bit VAs, pgdp=000000004fa51000 [ 881.106573] [0000000000000020] pgd=080000004f36e003, p4d=080000004f36e003, pud=080000004f7ec003, pmd=0000000000000000 [ 881.117217] Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP [ 881.123494] Modules linked in: rcar_fdp1 v4l2_mem2mem [ 881.128572] CPU: 0 PID: 1271 Comm: yavta Tainted: G B 6.2.0-rc1-00023-g6c94e2e99343 #556 [ 881.138061] Hardware name: Renesas Salvator-X 2nd version board based on r8a77965 (DT) [ 881.145981] pstate: 400000c5 (nZcv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 881.152951] pc : vsp1_dl_list_add_body+0xa8/0xe0 [ 881.157580] lr : vsp1_dl_list_add_body+0x34/0xe0 [ 881.162206] sp : ffff80000c267710 [ 881.165522] x29: ffff80000c267710 x28: ffff000010938ae8 x27: ffff000013a8dd98 [ 881.172683] x26: ffff000010938098 x25: ffff000013a8dc00 x24: ffff000010ed6ba8 [ 881.179841] x23: ffff00000faa4000 x22: 0000000000000000 x21: 0000000000000020 [ 881.186998] x20: ffff00000faa4000 x19: 0000000000000000 x18: 0000000000000000 [ 881.194154] x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 [ 881.201309] x14: 0000000000000000 x13: 746e696174206c65 x12: ffff70000157043d [ 881.208465] x11: 1ffff0000157043c x10: ffff70000157043c x9 : dfff800000000000 [ 881.215622] x8 : ffff80000ab821e7 x7 : 00008ffffea8fbc4 x6 : 0000000000000001 [ 881.222779] x5 : ffff80000ab821e0 x4 : ffff70000157043d x3 : 0000000000000020 [ 881.229936] x2 : 0000000000000020 x1 : ffff00000e4f6400 x0 : 0000000000000000 [ 881.237092] Call trace: [ 881.239542] vsp1_dl_list_add_body+0xa8/0xe0 [ 881.243822] vsp1_video_pipeline_run+0x270/0x2a0 [ 881.248449] vsp1_video_buffer_queue+0x1c0/0x1d0 [ 881.253076] __enqueue_in_driver+0xbc/0x260 [ 881.257269] vb2_start_streaming+0x48/0x200 [ 881.261461] vb2_core_streamon+0x13c/0x280 [ 881.265565] vb2_streamon+0x3c/0x90 [ 881.269064] vsp1_video_streamon+0x2fc/0x3e0 [ 881.273344] v4l_streamon+0x50/0x70 [ 881.276844] __video_do_ioctl+0x2bc/0x5d0 [ 881.280861] video_usercopy+0x2a8/0xc80 [ 881.284704] video_ioctl2+0x20/0x40 [ 881.288201] v4l2_ioctl+0xa4/0xc0 [ 881.291525] __arm64_sys_ioctl+0xe8/0x110 [ 881.295543] invoke_syscall+0x68/0x190 [ 881.299303] el0_svc_common.constprop.0+0x88/0x170 [ 881.304105] do_el0_svc+0x4c/0xf0 [ 881.307430] el0_svc+0x4c/0xa0 [ 881.310494] el0t_64_sync_handler+0xbc/0x140 [ 881.314773] el0t_64_sync+0x190/0x194 [ 881.318450] Code: d50323bf d65f03c0 91008263 f9800071 (885f7c60) [ 881.324551] ---[ end trace 0000000000000000 ]--- [ 881.329173] note: yavta[1271] exited with preempt_count 1
A different regression report sent to the linux-media mailing list ([1]) was answered with a claim that the vb2_is_streaming() function has never been meant for this purpose. The document of the function, as well as of the struct vb2_queue streaming field, is sparse, so this claim may be hard to verify.
The information needed by the vsp1 driver to decide how to process queued buffers is also available from the vb2_start_streaming_called() function. Use it instead of vb2_is_streaming() to fix the problem.
[1] https://lore.kernel.org/linux-media/[email protected]/
--- drivers/media/platform/renesas/vsp1/vsp1_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/renesas/vsp1/vsp1_video.c +1 -1
@@ -776,7 +776,7 @@ static void vsp1_video_buffer_queue(struct vb2_buffer *vb) video->rwpf->mem = buf->mem; pipe->buffers_ready |=1 << video->pipe_index; -if (vb2_is_streaming (&video->queue) && +if (vb2_start_streaming_called (&video->queue) &&vsp1_pipeline_ready (pipe))vsp1_video_pipeline_run (pipe);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 298/694 media: rcar_fdp1: Convert to platform remove callback returning void
In reply to Greg Kroah-HartmanFrom: Uwe Kleine-König <[email protected]>
[ Upstream commit 0e82d3715fd208de567b8e4307fbf91ae5e57db4 ]
The .remove() callback for a platform driver returns an int which makes many driver authors wrongly assume it's possible to do error handling by returning an error code. However the value returned is (mostly) ignored and this typically results in resource leaks. To improve here there is a quest to make the remove callback return void. In the first step of this quest all drivers are converted to .remove_new() which already returns void.
Trivially convert this driver from always returning zero in the remove callback to the void returning variant.
Stable-dep-of: c766c90faf93 ("media: rcar_fdp1: Fix refcount leak in probe and remove function")
--- drivers/media/platform/renesas/rcar_fdp1.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/platform/renesas/rcar_fdp1.c +2 -4
@@ -2396,7 +2396,7 @@ static int fdp1_probe(struct platform_device *pdev)return ret; } -static int fdp1_remove (struct platform_device *pdev) +static void fdp1_remove (struct platform_device *pdev) {struct fdp1_dev *fdp1 =platform_get_drvdata (pdev);
@@ -2404,8 +2404,6 @@ static int fdp1_remove(struct platform_device *pdev)video_unregister_device (&fdp1->vfd);v4l2_device_unregister (&fdp1->v4l2_dev);pm_runtime_disable (&pdev->dev); - -return 0 ; }static int __maybe_unused fdp1_pm_runtime_suspend (struct device *dev)
@@ -2441,7 +2439,7 @@ MODULE_DEVICE_TABLE(of, fdp1_dt_ids);static struct platform_driver fdp1_pdrv = { .probe = fdp1_probe, - .remove = fdp1_remove, + .remove_new = fdp1_remove, .driver = { .name =DRIVER_NAME , .of_match_table = fdp1_dt_ids,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 299/694 media: rcar_fdp1: Fix refcount leak in probe and remove function
In reply to Greg Kroah-HartmanFrom: Miaoqian Lin <[email protected]>
[ Upstream commit c766c90faf93897b77c9c5daa603cffab85ba907 ]
rcar_fcp_get() take reference, which should be balanced with rcar_fcp_put(). Add missing rcar_fcp_put() in fdp1_remove and the error paths of fdp1_probe() to fix this.
--- drivers/media/platform/renesas/rcar_fdp1.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/platform/renesas/rcar_fdp1.c +8 -3
@@ -2313,8 +2313,10 @@ static int fdp1_probe(struct platform_device *pdev)/* Determine our clock rate */ clk =clk_get (&pdev->dev,NULL ); -if (IS_ERR (clk)) -return PTR_ERR (clk); +if (IS_ERR (clk)) { + ret =PTR_ERR (clk); + goto put_dev; + } fdp1->clk_rate =clk_get_rate (clk);clk_put (clk);
@@ -2323,7 +2325,7 @@ static int fdp1_probe(struct platform_device *pdev) ret =v4l2_device_register (&pdev->dev, &fdp1->v4l2_dev);if (ret) {v4l2_err (&fdp1->v4l2_dev,"Failed to register video device\n" ); -return ret; + goto put_dev; }/* M2M registration */
@@ -2393,6 +2395,8 @@ static int fdp1_probe(struct platform_device *pdev) unreg_dev:v4l2_device_unregister (&fdp1->v4l2_dev); +put_dev: +rcar_fcp_put (fdp1->fcp);return ret; }
@@ -2404,6 +2408,7 @@ static void fdp1_remove(struct platform_device *pdev)video_unregister_device (&fdp1->vfd);v4l2_device_unregister (&fdp1->v4l2_dev);pm_runtime_disable (&pdev->dev); +rcar_fcp_put (fdp1->fcp); }static int __maybe_unused fdp1_pm_runtime_suspend (struct device *dev)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 300/694 media: v4l: async: Return async sub-devices to subnotifier list
In reply to Greg Kroah-HartmanFrom: Sakari Ailus <[email protected]>
[ Upstream commit 5276c9df9c2ab9a43b534bfb56bdb10899cd3a22 ]
When an async notifier is unregistered, the async sub-devices in the notifier's done list will disappear with the notifier. However this is currently also done to the sub-notifiers that remain registered. Their sub-devices only need to be unbound while the async sub-devices themselves need to be returned to the sub-notifier's waiting list. Do this now.
--- drivers/media/v4l2-core/v4l2-async.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-async.c +8 -5
@@ -416,7 +416,8 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd)/* Unbind all sub-devices in the notifier tree. */ static void -v4l2_async_nf_unbind_all_subdevs (struct v4l2_async_notifier *notifier) +v4l2_async_nf_unbind_all_subdevs (struct v4l2_async_notifier *notifier, +bool readd) {struct v4l2_subdev *sd, *tmp;
@@ -425,9 +426,11 @@ v4l2_async_nf_unbind_all_subdevs(struct v4l2_async_notifier *notifier)v4l2_async_find_subdev_notifier (sd);if (subdev_notifier) -v4l2_async_nf_unbind_all_subdevs (subdev_notifier); +v4l2_async_nf_unbind_all_subdevs (subdev_notifier, true);v4l2_async_nf_call_unbind (notifier, sd, sd->asd); +if (readd) +list_add_tail (&sd->asd->list, ¬ifier->waiting);v4l2_async_cleanup (sd);list_move (&sd->async_list, &subdev_list);
@@ -559,7 +562,7 @@ static int __v4l2_async_nf_register(struct v4l2_async_notifier *notifier)/* * On failure, unbind all sub-devices registered through this notifier. */ -v4l2_async_nf_unbind_all_subdevs (notifier); +v4l2_async_nf_unbind_all_subdevs (notifier, false); err_unlock:mutex_unlock (&list_lock);
@@ -609,7 +612,7 @@ __v4l2_async_nf_unregister(struct v4l2_async_notifier *notifier)if (!notifier || (!notifier->v4l2_dev && !notifier->sd))return ; -v4l2_async_nf_unbind_all_subdevs (notifier); +v4l2_async_nf_unbind_all_subdevs (notifier, false); notifier->sd =NULL ; notifier->v4l2_dev =NULL ;
@@ -807,7 +810,7 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)*/ subdev_notifier =v4l2_async_find_subdev_notifier (sd);if (subdev_notifier) -v4l2_async_nf_unbind_all_subdevs (subdev_notifier); +v4l2_async_nf_unbind_all_subdevs (subdev_notifier, false);if (sd->asd)v4l2_async_nf_call_unbind (notifier, sd, sd->asd);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 301/694 media: hi846: Fix memleak in hi846_init_controls()
In reply to Greg Kroah-HartmanFrom: Wei Chen <[email protected]>
[ Upstream commit 2649c1a20e8e399ee955d0e22192f9992662c3d2 ]
hi846_init_controls doesn't clean the allocated ctrl_hdlr in case there is a failure, which causes memleak. Add v4l2_ctrl_handler_free to free the resource properly.
--- drivers/media/i2c/hi846.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/media/i2c/hi846.c +8 -3
@@ -1472,21 +1472,26 @@ static int hi846_init_controls(struct hi846 *hi846)if (ctrl_hdlr->error) {dev_err (&client->dev,"v4l ctrl handler error: %d\n" , ctrl_hdlr->error); -return ctrl_hdlr->error; + ret = ctrl_hdlr->error; + goto error; } ret =v4l2_fwnode_device_parse (&client->dev, &props);if (ret) -return ret; + goto error; ret =v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &hi846_ctrl_ops, &props);if (ret) -return ret; + goto error; hi846->sd.ctrl_handler = ctrl_hdlr;return 0 ; + +error: +v4l2_ctrl_handler_free (ctrl_hdlr); +return ret; }static int hi846_set_video_mode (struct hi846 *hi846,int fps)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 302/694 drm/amd/display: Fix potential null dereference
In reply to Greg Kroah-HartmanFrom: Igor Artemiev <[email protected]>
[ Upstream commit 52f1783ff4146344342422c1cd94fcb4ce39b6fe ]
The adev->dm.dc pointer can be NULL and dereferenced in amdgpu_dm_fini() without checking.
Add a NULL pointer check before calling dc_dmub_srv_destroy().
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -1
@@ -1854,7 +1854,8 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev)dc_deinit_callbacks (adev->dm.dc);#endif -dc_dmub_srv_destroy (&adev->dm.dc->ctx->dmub_srv); +if (adev->dm.dc) +dc_dmub_srv_destroy (&adev->dm.dc->ctx->dmub_srv);if (dc_enable_dmub_notifications (adev->dm.dc)) {kfree (adev->dm.dmub_notify);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 303/694 media: rc: gpio-ir-recv: Fix support for wake-up
In reply to Greg Kroah-HartmanFrom: Florian Fainelli <[email protected]>
[ Upstream commit 9c592f8ab114875fdb3b2040f01818e53de44991 ]
The driver was intended from the start to be a wake-up source for the system, however due to the absence of a suitable call to device_set_wakeup_capable(), the device_may_wakeup() call used to decide whether to enable the GPIO interrupt as a wake-up source would never happen. Lookup the DT standard "wakeup-source" property and call device_init_wakeup() to ensure the device is flagged as being wakeup capable.
--- drivers/media/rc/gpio-ir-recv.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/rc/gpio-ir-recv.c +2 -0
@@ -103,6 +103,8 @@ static int gpio_ir_recv_probe(struct platform_device *pdev) rcdev->map_name =RC_MAP_EMPTY ; gpio_dev->rcdev = rcdev; +if (of_property_read_bool (np,"wakeup-source" )) +device_init_wakeup (dev, true); rc =devm_rc_register_device (dev, rcdev);if (rc <0 ) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 304/694 media: venus: dec: Fix handling of the start cmd
In reply to Greg Kroah-HartmanFrom: Michał Krawczyk <[email protected]>
[ Upstream commit 50248ad9f190d527cbd578190ca769729518b703 ]
The decoder driver should clear the last_buffer_dequeued flag of the capture queue upon receiving V4L2_DEC_CMD_START.
The last_buffer_dequeued flag is set upon receiving EOS (which always happens upon receiving V4L2_DEC_CMD_STOP).
Without this patch, after issuing the V4L2_DEC_CMD_STOP and V4L2_DEC_CMD_START, the vb2_dqbuf() function will always fail, even if the buffers are completed by the hardware.
--- drivers/media/platform/qcom/venus/vdec.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/platform/qcom/venus/vdec.c +8 -0
@@ -526,6 +526,7 @@ static int vdec_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *cmd) { struct venus_inst *inst = to_inst(file); +struct vb2_queue *dst_vq;struct hfi_frame_data fdata = {0 };int ret;
@@ -556,6 +557,13 @@ vdec_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *cmd) inst->codec_state =VENUS_DEC_STATE_DRAIN ; inst->drain_active = true; } + }else if (cmd->cmd ==V4L2_DEC_CMD_START && + inst->codec_state ==VENUS_DEC_STATE_STOPPED ) { + dst_vq =v4l2_m2m_get_vq (inst->fh.m2m_ctx, +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); +vb2_clear_last_buffer_dequeued (dst_vq); + + inst->codec_state =VENUS_DEC_STATE_DECODING ; } unlock:
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 305/694 media: venus: dec: Fix capture formats enumeration order
In reply to Greg Kroah-HartmanFrom: Javier Martinez Canillas <[email protected]>
[ Upstream commit a9d45ec74c8e68aaafe90191928eddbf79f4644f ]
Commit 9593126dae3e ("media: venus: Add a handling of QC08C compressed format") and commit cef92b14e653 ("media: venus: Add a handling of QC10C compressed format") added support for the QC08C and QC10C compressed formats respectively.
But these also caused a regression, because the new formats where added at the beginning of the vdec_formats[] array and the vdec_inst_init() function sets the default format output and capture using fixed indexes of that array:
static void vdec_inst_init(struct venus_inst *inst) {
...
inst->fmt_out = &vdec_formats[8]; inst->fmt_cap = &vdec_formats[0];
...
}
Since now V4L2_PIX_FMT_NV12 is not the first entry in the array anymore, the default capture format is not set to that as it was done before.
Both commits changed the first index to keep inst->fmt_out default format set to V4L2_PIX_FMT_H264, but did not update the latter to keep .fmt_out default format set to V4L2_PIX_FMT_NV12.
Rather than updating the index to the current V4L2_PIX_FMT_NV12 position, let's reorder the entries so that this format is the first entry again.
This would also make VIDIOC_ENUM_FMT report the V4L2_PIX_FMT_NV12 format with an index 0 as it did before the QC08C and QC10C formats were added.
--- drivers/media/platform/qcom/venus/vdec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/venus/vdec.c +4 -4
@@ -31,15 +31,15 @@*/ static const struct venus_format vdec_formats[] = { { - .pixfmt =V4L2_PIX_FMT_QC08C , + .pixfmt =V4L2_PIX_FMT_NV12 , .num_planes =1 , .type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE , }, { - .pixfmt =V4L2_PIX_FMT_QC10C , + .pixfmt =V4L2_PIX_FMT_QC08C , .num_planes =1 , .type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE , - },{ - .pixfmt =V4L2_PIX_FMT_NV12 , + }, { + .pixfmt =V4L2_PIX_FMT_QC10C , .num_planes =1 , .type =V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE , }, {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 306/694 regulator: stm32-pwr: fix of_iomap leak
In reply to Greg Kroah-HartmanFrom: YAN SHI <[email protected]>
[ Upstream commit c4a413e56d16a2ae84e6d8992f215c4dcc7fac20 ]
Smatch reports:drivers/regulator/stm32-pwr.c:166 stm32_pwr_regulator_probe() warn:
'base' from of_iomap() not released on lines: 151,166.
In stm32_pwr_regulator_probe(), base is not released when devm_kzalloc() fails to allocate memory or devm_regulator_register() fails to register a new regulator device, which may cause a leak.
To fix this issue, replace of_iomap() with devm_platform_ioremap_resource(). devm_platform_ioremap_resource() is a specialized function for platform devices.
It allows 'base' to be automatically released whether the probe function succeeds or fails.
Besides, use IS_ERR(base) instead of !base
as the return value of devm_platform_ioremap_resource() can either be a pointer to the remapped memory or an ERR_PTR() encoded error code if the operation fails.
--- drivers/regulator/stm32-pwr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/regulator/stm32-pwr.c +3 -4
@@ -129,17 +129,16 @@ static const struct regulator_desc stm32_pwr_desc[] = {static int stm32_pwr_regulator_probe (struct platform_device *pdev) { -struct device_node *np = pdev->dev.of_node;struct stm32_pwr_reg *priv;void __iomem *base;struct regulator_dev *rdev;struct regulator_config config = { };int i, ret =0 ; - base =of_iomap (np,0 ); -if (!base) { + base =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (base)) {dev_err (&pdev->dev,"Unable to map IO memory\n" ); -return -ENOMEM ; +return PTR_ERR (base); } config.dev = &pdev->dev;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 307/694 x86/ioapic: Dont return 0 from arch_dynirq_lower_bound()
In reply to Greg Kroah-HartmanFrom: Saurabh Sengar <[email protected]>
[ Upstream commit 5af507bef93c09a94fb8f058213b489178f4cbe5 ]
arch_dynirq_lower_bound() is invoked by the core interrupt code to retrieve the lowest possible Linux interrupt number for dynamically allocated interrupts like MSI.
The x86 implementation uses this to exclude the IO/APIC GSI space. This works correctly as long as there is an IO/APIC registered, but returns 0 if not. This has been observed in VMs where the BIOS does not advertise an IO/APIC.
0 is an invalid interrupt number except for the legacy timer interrupt on x86. The return value is unchecked in the core code, so it ends up to allocate interrupt number 0 which is subsequently considered to be invalid by the caller, e.g. the MSI allocation code.
The function has already a check for 0 in the case that an IO/APIC is registered, as ioapic_dynirq_base is 0 in case of device tree setups.
Consolidate this and zero check for both ioapic_dynirq_base and gsi_top, which is used in the case that no IO/APIC is registered.
--- arch/x86/kernel/apic/io_apic.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
arch/x86/kernel/apic/io_apic.c +9 -5
@@ -2477,17 +2477,21 @@ static int io_apic_get_redir_entries(int ioapic)unsigned int arch_dynirq_lower_bound (unsigned int from) { +unsigned int ret; +/* * dmar_alloc_hwirq() may be called before setup_IO_APIC(), so use * gsi_top if ioapic_dynirq_base hasn't been initialized yet. */ -if (!ioapic_initialized) -return gsi_top; + ret = ioapic_dynirq_base ? : gsi_top; +/* -* For DT enabled machines ioapic_dynirq_base is irrelevant and not -* updated. So simply return @from if ioapic_dynirq_base == 0. +* For DT enabled machines ioapic_dynirq_base is irrelevant and +* always 0. gsi_top can be 0 if there is no IO/APIC registered. +* 0 is an invalid interrupt number for dynamic allocations. Return +* @from instead. */ -return ioapic_dynirq_base ? : from; +return ret ? : from; }#ifdef CONFIG_X86_32
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 308/694 arm64: kgdb: Set PSTATE.SS to 1 to re-enable single-step
In reply to Greg Kroah-HartmanFrom: Sumit Garg <[email protected]>
[ Upstream commit af6c0bd59f4f3ad5daad2f7b777954b1954551d5 ]
Currently only the first attempt to single-step has any effect. After that all further stepping remains "stuck" at the same program counter value.
Refer to the ARM Architecture Reference Manual (ARM DDI 0487E.a) D2.12, PSTATE.SS=1 should be set at each step before transferring the PE to the 'Active-not-pending' state. The problem here is PSTATE.SS=1 is not set since the second single-step.
After the first single-step, the PE transferes to the 'Inactive' state, with PSTATE.SS=0 and MDSCR.SS=1, thus PSTATE.SS won't be set to 1 due to kernel_active_single_step()=true. Then the PE transferes to the 'Active-pending' state when ERET and returns to the debugger by step exception.
Before this patch:
==================
Entering kdb (current=0xffff3376039f0000, pid 1) on processor 0 due to Keyboard Entry [0]kdb>
[0]kdb>
[0]kdb> bp write_sysrq_trigger
Instruction(i) BP #0 at 0xffffa45c13d09290 (write_sysrq_trigger)
is enabled addr at ffffa45c13d09290, hardtype=0 installed=0
[0]kdb> go
$ echo h > /proc/sysrq-trigger
Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to Breakpoint @ 0xffffad651a309290 [1]kdb> ss
Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to SS trap @ 0xffffad651a309294 [1]kdb> ss
Entering kdb (current=0xffff4f7e453f8000, pid 175) on processor 1 due to SS trap @ 0xffffad651a309294 [1]kdb>
After this patch:
=================
Entering kdb (current=0xffff6851c39f0000, pid 1) on processor 0 due to Keyboard Entry [0]kdb> bp write_sysrq_trigger
Instruction(i) BP #0 at 0xffffc02d2dd09290 (write_sysrq_trigger)
is enabled addr at ffffc02d2dd09290, hardtype=0 installed=0
[0]kdb> go
$ echo h > /proc/sysrq-trigger
Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to Breakpoint @ 0xffffc02d2dd09290 [1]kdb> ss
Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd09294 [1]kdb> ss
Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd09298 [1]kdb> ss
Entering kdb (current=0xffff6851c53c1840, pid 174) on processor 1 due to SS trap @ 0xffffc02d2dd0929c [1]kdb>
--- arch/arm64/include/asm/debug-monitors.h | 1 + arch/arm64/kernel/debug-monitors.c | 5 +++++ arch/arm64/kernel/kgdb.c | 2 ++ 3 files changed, 8 insertions(+)
arch/arm64/include/asm/debug-monitors.h +1 -0
@@ -104,6 +104,7 @@ void user_regs_reset_single_step(struct user_pt_regs *regs,void kernel_enable_single_step (struct pt_regs *regs);void kernel_disable_single_step (void );int kernel_active_single_step (void ); +void kernel_rewind_single_step (struct pt_regs *regs);#ifdef CONFIG_HAVE_HW_BREAKPOINT int reinstall_suspended_bps (struct pt_regs *regs);
arch/arm64/kernel/debug-monitors.c +5 -0
@@ -438,6 +438,11 @@ int kernel_active_single_step(void) }NOKPROBE_SYMBOL (kernel_active_single_step); +void kernel_rewind_single_step (struct pt_regs *regs) +{ +set_regs_spsr_ss (regs); +} +/* ptrace API */ void user_enable_single_step (struct task_struct *task) {
arch/arm64/kernel/kgdb.c +2 -0
@@ -224,6 +224,8 @@ int kgdb_arch_handle_exception(int exception_vector, int signo,*/ if (!kernel_active_single_step ())kernel_enable_single_step (linux_regs); +else +kernel_rewind_single_step (linux_regs); err =0 ;break ;default :
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 309/694 perf/arm-cmn: Fix port detection for CMN-700
In reply to Greg Kroah-HartmanFrom: Robin Murphy <[email protected]>
[ Upstream commit 2ad91e44e6b0c7ef1ed151b3bb2242a2144e6085 ]
When the "extra device ports" configuration was first added, the additional mxp_device_port_connect_info registers were added around the existing mxp_mesh_port_connect_info registers. What I missed about CMN-700 is that it shuffled them around to remove this discontinuity. As such, tweak the definitions and factor out a helper for reading these registers so we can deal with this discrepancy easily, which does at least allow nicely tidying up the callsites. With this we can then also do the nice thing and skip accesses completely rather than relying on RES0 behaviour where we know the extra registers aren't defined.
--- drivers/perf/arm-cmn.c | 57 ++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 27 deletions(-)
drivers/perf/arm-cmn.c +30 -27
@@ -57,14 +57,12 @@#define CMN_INFO_REQ_VC_NUM GENMASK_ULL(1, 0)/* XPs also have some local topology info which has uses too */ -#define CMN_MXP__CONNECT_INFO_P0 0x0008 -#define CMN_MXP__CONNECT_INFO_P1 0x0010 -#define CMN_MXP__CONNECT_INFO_P2 0x0028 -#define CMN_MXP__CONNECT_INFO_P3 0x0030 -#define CMN_MXP__CONNECT_INFO_P4 0x0038 -#define CMN_MXP__CONNECT_INFO_P5 0x0040 +#define CMN_MXP__CONNECT_INFO (p) (0x0008 + 8 * (p))#define CMN__CONNECT_INFO_DEVICE_TYPE GENMASK_ULL(4, 0) +#define CMN_MAX_PORTS 6 +#define CI700_CONNECT_INFO_P2_5_OFFSET 0x10 +/* PMU registers occupy the 3rd 4KB page of each node's region */ #define CMN_PMU_OFFSET 0x2000
@@ -396,6 +394,25 @@ static struct arm_cmn_node *arm_cmn_node(const struct arm_cmn *cmn,return NULL ; } +static u32 arm_cmn_device_connect_info (const struct arm_cmn *cmn, +const struct arm_cmn_node *xp,int port) +{ +int offset =CMN_MXP__CONNECT_INFO (port); + +if (port >=2 ) { +if (cmn->model & (CMN600 |CMN650 )) +return 0 ; +/* +* CI-700 may have extra ports, but still has the +* mesh_port_connect_info registers in the way. +*/ +if (cmn->model ==CI700 ) + offset +=CI700_CONNECT_INFO_P2_5_OFFSET ; + } + +return readl_relaxed (xp->pmu_base -CMN_PMU_OFFSET + offset); +} +static struct dentry *arm_cmn_debugfs;#ifdef CONFIG_DEBUG_FS
@@ -469,7 +486,7 @@ static int arm_cmn_map_show(struct seq_file *s, void *data) y = cmn->mesh_y;while (y--) {int xp_base = cmn->mesh_x * y; -u8 port[6 ][CMN_MAX_DIMENSION ]; +u8 port[CMN_MAX_PORTS ][CMN_MAX_DIMENSION ];for (x =0 ; x < cmn->mesh_x; x++)seq_puts (s,"--------+" );
@@ -477,14 +494,9 @@ static int arm_cmn_map_show(struct seq_file *s, void *data)seq_printf (s,"\n%d |" , y);for (x =0 ; x < cmn->mesh_x; x++) {struct arm_cmn_node *xp = cmn->xps + xp_base + x; -void __iomem *base = xp->pmu_base -CMN_PMU_OFFSET ; - - port[0 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P0 ); - port[1 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P1 ); - port[2 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P2 ); - port[3 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P3 ); - port[4 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P4 ); - port[5 ][x] =readl_relaxed (base +CMN_MXP__CONNECT_INFO_P5 ); + +for (p =0 ; p <CMN_MAX_PORTS ; p++) + port[p][x] =arm_cmn_device_connect_info (cmn, xp, p);seq_printf (s," XP #%-2d |" , xp_base + x); }
@@ -2083,18 +2095,9 @@ static int arm_cmn_discover(struct arm_cmn *cmn, unsigned int rgn_offset)* from this, since in that case we will see at least one XP * with port 2 connected, for the HN-D. */ -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P0 )) - xp_ports |=BIT (0 ); -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P1 )) - xp_ports |=BIT (1 ); -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P2 )) - xp_ports |=BIT (2 ); -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P3 )) - xp_ports |=BIT (3 ); -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P4 )) - xp_ports |=BIT (4 ); -if (readq_relaxed (xp_region +CMN_MXP__CONNECT_INFO_P5 )) - xp_ports |=BIT (5 ); +for (int p =0 ; p <CMN_MAX_PORTS ; p++) +if (arm_cmn_device_connect_info (cmn, xp, p)) + xp_ports |=BIT (p);if (cmn->multi_dtm && (xp_ports &0xc ))arm_cmn_init_dtm (dtm++, xp,1 );
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 310/694 media: mediatek: vcodec: fix decoder disable pm crash
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit 9d2f13fb47dcab6d094f34ecfd6a879a409722b3 ]
Can't call pm_runtime_disable when the architecture support sub device for 'dev->pm.dev' is NUll, or will get below crash log.
[ 10.771551] pc : _raw_spin_lock_irq+0x4c/0xa0 [ 10.771556] lr : __pm_runtime_disable+0x30/0x130 [ 10.771558] sp : ffffffc01e4cb800 [ 10.771559] x29: ffffffc01e4cb800 x28: ffffffdf082108a8 [ 10.771563] x27: ffffffc01e4cbd70 x26: ffffff8605df55f0 [ 10.771567] x25: 0000000000000002 x24: 0000000000000002 [ 10.771570] x23: ffffff85c0dc9c00 x22: 0000000000000001 [ 10.771573] x21: 0000000000000001 x20: 0000000000000000 [ 10.771577] x19: 00000000000000f4 x18: ffffffdf2e9fbe18 [ 10.771580] x17: 0000000000000000 x16: ffffffdf2df13c74 [ 10.771583] x15: 00000000000002ea x14: 0000000000000058 [ 10.771587] x13: ffffffdf2de1b62c x12: ffffffdf2e9e30e4 [ 10.771590] x11: 0000000000000000 x10: 0000000000000001 [ 10.771593] x9 : 0000000000000000 x8 : 00000000000000f4 [ 10.771596] x7 : 6bff6264632c6264 x6 : 0000000000008000 [ 10.771600] x5 : 0080000000000000 x4 : 0000000000000001 [ 10.771603] x3 : 0000000000000008 x2 : 0000000000000001 [ 10.771608] x1 : 0000000000000000 x0 : 00000000000000f4 [ 10.771613] Call trace: [ 10.771617] _raw_spin_lock_irq+0x4c/0xa0 [ 10.771620] __pm_runtime_disable+0x30/0x130 [ 10.771657] mtk_vcodec_probe+0x69c/0x728 [mtk_vcodec_dec 800cc929d6631f79f9b273254c8db94d0d3500dc] [ 10.771662] platform_drv_probe+0x9c/0xbc [ 10.771665] really_probe+0x13c/0x3a0 [ 10.771668] driver_probe_device+0x84/0xc0 [ 10.771671] device_driver_attach+0x54/0x78
--- drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c +2 -1
@@ -451,7 +451,8 @@ static int mtk_vcodec_probe(struct platform_device *pdev)if (IS_VDEC_LAT_ARCH (dev->vdec_pdata->hw_arch))destroy_workqueue (dev->core_workqueue); err_res: -pm_runtime_disable (dev->pm.dev); +if (!dev->vdec_pdata->is_subdev_supported) +pm_runtime_disable (dev->pm.dev); err_dec_pm:mtk_vcodec_fw_release (dev->fw_handler);return ret;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 311/694 media: mediatek: vcodec: add remove function for decoder platform driver
In reply to Greg Kroah-HartmanFrom: Yunfei Dong <[email protected]>
[ Upstream commit e2a10b3801061d05d3e3415b9b824251451cfd6c ]
Need to disable decoder power when remove decoder hardware driver, adding remove callback function in the definition of platform driver.
--- .../media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_hw.c +8 -0
@@ -193,8 +193,16 @@ static int mtk_vdec_hw_probe(struct platform_device *pdev)return ret; } +static int mtk_vdec_hw_remove (struct platform_device *pdev) +{ +pm_runtime_disable (&pdev->dev); + +return 0 ; +} +static struct platform_driver mtk_vdec_driver = { .probe = mtk_vdec_hw_probe, + .remove = mtk_vdec_hw_remove, .driver = { .name ="mtk-vdec-comp" , .of_match_table = mtk_vdec_hw_match,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 312/694 debugobject: Prevent init race with static objects
In reply to Greg Kroah-HartmanFrom: Thomas Gleixner <[email protected]>
[ Upstream commit 63a759694eed61025713b3e14dd827c8548daadc ]
Statically initialized objects are usually not initialized via the init() function of the subsystem. They are special cased and the subsystem provides a function to validate whether an object which is not yet tracked by debugobjects is statically initialized. This means the object is started to be tracked on first use, e.g. activation.
This works perfectly fine, unless there are two concurrent operations on that object. Schspa decoded the problem:
T0 T1
debug_object_assert_init(addr)
lock_hash_bucket()
obj = lookup_object(addr);
if (!obj) {
unlock_hash_bucket();
- > preemption
lock_subsytem_object(addr);
activate_object(addr)
lock_hash_bucket();
obj = lookup_object(addr);
if (!obj) {
unlock_hash_bucket();
if (is_static_object(addr))
init_and_track(addr);
lock_hash_bucket();
obj = lookup_object(addr);
obj->state = ACTIVATED;
unlock_hash_bucket();
subsys function modifies content of addr,
so static object detection does
not longer work.
unlock_subsytem_object(addr);
if (is_static_object(addr)) <- Fails
debugobject emits a warning and invokes the fixup function which
reinitializes the already active object in the worst case.This race exists forever, but was never observed until mod_timer() got a debug_object_assert_init() added which is outside of the timer base lock held section right at the beginning of the function to cover the lockless early exit points too.
Rework the code so that the lookup, the static object check and the tracking object association happens atomically under the hash bucket lock. This prevents the issue completely as all callers are serialized on the hash bucket lock and therefore cannot observe inconsistent state.
--- lib/debugobjects.c | 125 ++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 59 deletions(-)
lib/debugobjects.c +66 -59
@@ -216,10 +216,6 @@ static struct debug_obj *__alloc_object(struct hlist_head *list)return obj; } -/* -* Allocate a new object. If the pool is empty, switch off the debugger. -* Must be called with interrupts disabled. -*/ static struct debug_obj *alloc_object (void *addr,struct debug_bucket *b,const struct debug_obj_descr *descr) {
@@ -552,11 +548,49 @@ static void debug_object_is_on_stack(void *addr, int onstack)WARN_ON (1 ); } +static struct debug_obj *lookup_object_or_alloc (void *addr,struct debug_bucket *b, +const struct debug_obj_descr *descr, +bool onstack,bool alloc_ifstatic) +{ +struct debug_obj *obj =lookup_object (addr, b); +enum debug_obj_state state =ODEBUG_STATE_NONE ; + +if (likely (obj)) +return obj; + +/* +* debug_object_init() unconditionally allocates untracked +* objects. It does not matter whether it is a static object or +* not. +* +* debug_object_assert_init() and debug_object_activate() allow +* allocation only if the descriptor callback confirms that the +* object is static and considered initialized. For non-static +* objects the allocation needs to be done from the fixup callback. +*/ +if (unlikely (alloc_ifstatic)) { +if (!descr->is_static_object || !descr->is_static_object (addr)) +return ERR_PTR (-ENOENT ); +/* Statically allocated objects are considered initialized */ + state =ODEBUG_STATE_INIT ; + } + + obj =alloc_object (addr, b, descr); +if (likely (obj)) { + obj->state = state; +debug_object_is_on_stack (addr, onstack); +return obj; + } + +/* Out of memory. Do the cleanup outside of the locked region */ + debug_objects_enabled =0 ; +return NULL ; +} +static void __debug_object_init (void *addr,const struct debug_obj_descr *descr,int onstack) {enum debug_obj_state state; -bool check_stack = false;struct debug_bucket *db;struct debug_obj *obj;unsigned long flags;
@@ -572,16 +606,11 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstackraw_spin_lock_irqsave (&db->lock, flags); - obj =lookup_object (addr, db); -if (!obj) { - obj =alloc_object (addr, db, descr); -if (!obj) { - debug_objects_enabled =0 ; -raw_spin_unlock_irqrestore (&db->lock, flags); -debug_objects_oom (); -return ; - } - check_stack = true; + obj =lookup_object_or_alloc (addr, db, descr, onstack, false); +if (unlikely (!obj)) { +raw_spin_unlock_irqrestore (&db->lock, flags); +debug_objects_oom (); +return ; }switch (obj->state) {
@@ -607,8 +636,6 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack }raw_spin_unlock_irqrestore (&db->lock, flags); -if (check_stack) -debug_object_is_on_stack (addr, onstack); }/**
@@ -648,14 +675,12 @@ EXPORT_SYMBOL_GPL(debug_object_init_on_stack);*/ int debug_object_activate (void *addr,const struct debug_obj_descr *descr) { +struct debug_obj o = { .object = addr, .state =ODEBUG_STATE_NOTAVAILABLE , .descr = descr };enum debug_obj_state state;struct debug_bucket *db;struct debug_obj *obj;unsigned long flags;int ret; -struct debug_obj o = { .object = addr, - .state =ODEBUG_STATE_NOTAVAILABLE , - .descr = descr };if (!debug_objects_enabled)return 0 ;
@@ -664,8 +689,8 @@ int debug_object_activate(void *addr, const struct debug_obj_descr *descr)raw_spin_lock_irqsave (&db->lock, flags); - obj =lookup_object (addr, db); -if (obj) { + obj =lookup_object_or_alloc (addr, db, descr, false, true); +if (likely (!IS_ERR_OR_NULL (obj))) {bool print_object = false;switch (obj->state) {
@@ -698,24 +723,16 @@ int debug_object_activate(void *addr, const struct debug_obj_descr *descr)raw_spin_unlock_irqrestore (&db->lock, flags); -/* -* We are here when a static object is activated. We -* let the type specific code confirm whether this is -* true or not. if true, we just make sure that the -* static object is tracked in the object tracker. If -* not, this must be a bug, so we try to fix it up. -*/ -if (descr->is_static_object && descr->is_static_object (addr)) { -/* track this static object */ -debug_object_init (addr, descr); -debug_object_activate (addr, descr); - }else { -debug_print_object (&o,"activate" ); - ret =debug_object_fixup (descr->fixup_activate, addr, -ODEBUG_STATE_NOTAVAILABLE ); -return ret ?0 : -EINVAL ; +/* If NULL the allocation has hit OOM */ +if (!obj) { +debug_objects_oom (); +return 0 ; } -return 0 ; + +/* Object is neither static nor tracked. It's not initialized */ +debug_print_object (&o,"activate" ); + ret =debug_object_fixup (descr->fixup_activate, addr,ODEBUG_STATE_NOTAVAILABLE ); +return ret ?0 : -EINVAL ; }EXPORT_SYMBOL_GPL (debug_object_activate);
@@ -869,6 +886,7 @@ EXPORT_SYMBOL_GPL(debug_object_free);*/ void debug_object_assert_init (void *addr,const struct debug_obj_descr *descr) { +struct debug_obj o = { .object = addr, .state =ODEBUG_STATE_NOTAVAILABLE , .descr = descr };struct debug_bucket *db;struct debug_obj *obj;unsigned long flags;
@@ -879,31 +897,20 @@ void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) db =get_bucket ((unsigned long ) addr);raw_spin_lock_irqsave (&db->lock, flags); + obj =lookup_object_or_alloc (addr, db, descr, false, true); +raw_spin_unlock_irqrestore (&db->lock, flags); +if (likely (!IS_ERR_OR_NULL (obj))) +return ; - obj =lookup_object (addr, db); +/* If NULL the allocation has hit OOM */ if (!obj) { -struct debug_obj o = { .object = addr, - .state =ODEBUG_STATE_NOTAVAILABLE , - .descr = descr }; - -raw_spin_unlock_irqrestore (&db->lock, flags); -/* -* Maybe the object is static, and we let the type specific -* code confirm. Track this static object if true, else invoke -* fixup. -*/ -if (descr->is_static_object && descr->is_static_object (addr)) { -/* Track this static object */ -debug_object_init (addr, descr); - }else { -debug_print_object (&o,"assert_init" ); -debug_object_fixup (descr->fixup_assert_init, addr, -ODEBUG_STATE_NOTAVAILABLE ); - } +debug_objects_oom ();return ; } -raw_spin_unlock_irqrestore (&db->lock, flags); +/* Object is neither tracked nor static. It's not initialized. */ +debug_print_object (&o,"assert_init" ); +debug_object_fixup (descr->fixup_assert_init, addr,ODEBUG_STATE_NOTAVAILABLE ); }EXPORT_SYMBOL_GPL (debug_object_assert_init);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 313/694 drm/i915: Make intel_get_crtc_new_encoder() less oopsy
In reply to Greg Kroah-HartmanFrom: Ville Syrjälä <[email protected]>
[ Upstream commit 631420b06597a33c72b6dcef78d1c2dea17f452d ]
The point of the WARN was to print something, not oops straight up. Currently that is precisely what happens if we can't find the connector for the crtc in the atomic state. Get the dev pointer from the atomic state instead of the potentially NULL encoder to avoid that.
--- drivers/gpu/drm/i915/display/intel_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_display.c +1 -1
@@ -1053,7 +1053,7 @@ intel_get_crtc_new_encoder(const struct intel_atomic_state *state, num_encoders++; } -drm_WARN (encoder->base.dev, num_encoders !=1 , +drm_WARN (state->base.dev, num_encoders !=1 ,"%d encoders for pipe %c\n" , num_encoders,pipe_name (master_crtc->pipe));
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 314/694 drm/i915: Fix memory leaks in i915 selftests
In reply to Greg Kroah-HartmanFrom: Cong Liu <[email protected]>
[ Upstream commit 803033c148f754f32da1b93926c49c22731ec485 ]
This patch fixes memory leaks on error escapes in function fake_get_pages
--- drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c +3 -1
@@ -69,8 +69,10 @@ static int fake_get_pages(struct drm_i915_gem_object *obj) rem =round_up (obj->base.size,BIT (31 )) >>31 ;/* restricted by sg_alloc_table */ - if (overflows_type(rem, unsigned int)) + if (overflows_type(rem, unsigned int)) { +kfree (pages);return -E2BIG ; + }if (sg_alloc_table (pages, rem,GFP )) {kfree (pages);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 315/694 tick/common: Align tick period with the HZ tick.
In reply to Greg Kroah-HartmanFrom: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit e9523a0d81899361214d118ad60ef76f0e92f71d ]
With HIGHRES enabled tick_sched_timer() is programmed every jiffy to expire the timer_list timers. This timer is programmed accurate in respect to CLOCK_MONOTONIC so that 0 seconds and nanoseconds is the first tick and the next one is 1000/CONFIG_HZ ms later. For HZ=250 it is every 4 ms and so based on the current time the next tick can be computed.
This accuracy broke since the commit mentioned below because the jiffy based clocksource is initialized with higher accuracy in read_persistent_wall_and_boot_offset(). This higher accuracy is inherited during the setup in tick_setup_device(). The timer still fires every 4ms with HZ=250 but timer is no longer aligned with CLOCK_MONOTONIC with 0 as it origin but has an offset in the us/ns part of the timestamp. The offset differs with every boot and makes it impossible for user land to align with the tick.
Align the tick period with CLOCK_MONOTONIC ensuring that it is always a multiple of 1000/CONFIG_HZ ms.
--- kernel/time/tick-common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
kernel/time/tick-common.c +11 -1
@@ -218,9 +218,19 @@ static void tick_setup_device(struct tick_device *td,* this cpu: */ if (tick_do_timer_cpu ==TICK_DO_TIMER_BOOT ) { +ktime_t next_p; +u32 rem; + tick_do_timer_cpu = cpu; - tick_next_period =ktime_get (); + next_p =ktime_get (); +div_u64_rem (next_p,TICK_NSEC , &rem); +if (rem) { + next_p -= rem; + next_p +=TICK_NSEC ; + } + + tick_next_period = next_p;#ifdef CONFIG_NO_HZ_FULL /* * The boot CPU may be nohz_full, in which case set
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 316/694 ACPI: bus: Ensure that notify handlers are not running after removal
In reply to Greg Kroah-HartmanFrom: Rafael J. Wysocki <[email protected]>
[ Upstream commit faae443738c6f0dac9b0d3d11d108f6911a989a9 ]
Currently, acpi_device_remove_notify_handler() may return while the notify handler being removed is still running which may allow the module holding that handler to be torn down prematurely.
Address this issue by making acpi_device_remove_notify_handler() wait for the handling of all the ACPI events in progress to complete before returning.
--- drivers/acpi/bus.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/bus.c +1 -0
@@ -589,6 +589,7 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device,acpi_remove_notify_handler (device->handle, type, acpi_notify_device); } +acpi_os_wait_events_complete (); }/* Handle events targeting \_SB device (at present only graceful shutdown) */
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 317/694 cpufreq: use correct unit when verify cur freq
In reply to Greg Kroah-HartmanFrom: Sanjay Chandrashekara <[email protected]>
[ Upstream commit 44295af5019f1997d038ad2611086a2d1e2af167 ]
cpufreq_verify_current_freq checks() if the frequency returned by the hardware has a slight delta with the valid frequency value last set and returns "policy->cur" if the delta is within "1 MHz". In the comparison, "policy->cur" is in "kHz" but it's compared against HZ_PER_MHZ. So, the comparison range becomes "1 GHz".
Fix this by comparing against KHZ_PER_MHZ instead of HZ_PER_MHZ.
--- drivers/cpufreq/cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
@@ -1727,7 +1727,7 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b* MHz. In such cases it is better to avoid getting into * unnecessary frequency updates. */ -if (abs (policy->cur - new_freq) <HZ_PER_MHZ ) +if (abs (policy->cur - new_freq) <KHZ_PER_MHZ )return policy->cur;cpufreq_out_of_sync (policy, new_freq);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 318/694 rpmsg: glink: Propagate TX failures in intentless mode as well
In reply to Greg Kroah-HartmanFrom: Bjorn Andersson <[email protected]>
[ Upstream commit 7a68f9fa97357a0f2073c9c31ed4101da4fce93e ]
As support for splitting transmission over several messages using TX_DATA_CONT was introduced it does not immediately return the return value of qcom_glink_tx().
The result is that in the intentless case (i.e. intent == NULL), the code will continue to send all additional chunks. This is wasteful, and it's possible that the send operation could incorrectly indicate success, if the last chunk fits in the TX fifo.
Fix the condition.
--- drivers/rpmsg/qcom_glink_native.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/rpmsg/qcom_glink_native.c +6 -4
@@ -1356,8 +1356,9 @@ static int __qcom_glink_send(struct glink_channel *channel, ret =qcom_glink_tx (glink, &req,sizeof (req), data, chunk_size, wait);/* Mark intent available if we failed */ -if (ret && intent) { - intent->in_use = false; +if (ret) { +if (intent) + intent->in_use = false;return ret; }
@@ -1378,8 +1379,9 @@ static int __qcom_glink_send(struct glink_channel *channel, chunk_size, wait);/* Mark intent available if we failed */ -if (ret && intent) { - intent->in_use = false; +if (ret) { +if (intent) + intent->in_use = false;break ; } }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 319/694 hwmon: (pmbus/fsp-3y) Fix functionality bitmask in FSP-3Y YM-2151E
In reply to Greg Kroah-HartmanFrom: Tomáš Pecka <[email protected]>
[ Upstream commit 93822f5161a2dc57a60b95b35b3cb8589f53413e ]
The bit flags in pmbus_driver_info functionality for YM-2151E chip were joined with a comma operator instead of a bitwise OR. This means that the last constant PMBUS_HAVE_IIN was not OR-ed with the other PM_BUS_HAVE_* constants for this page but it initialized the next element of the func array (which was not accessed from anywhere because of the number of pages).
However, there is no need for setting PMBUS_HAVE_IIN in the 5Vsb page because this command does not seem to be paged. Obviously, the device only has one IIN sensor, so it doesn't make sense to query it again from the second page.
--- drivers/hwmon/pmbus/fsp-3y.c | 1 - 1 file changed, 1 deletion(-)
drivers/hwmon/pmbus/fsp-3y.c +0 -1
@@ -180,7 +180,6 @@ static struct pmbus_driver_info fsp3y_info[] = { PMBUS_HAVE_FAN12, .func[YM2151_PAGE_5VSB_LOG ] = PMBUS_HAVE_VOUT | PMBUS_HAVE_IOUT, -PMBUS_HAVE_IIN , .read_word_data = fsp3y_read_word_data, .read_byte_data = fsp3y_read_byte_data, },
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 320/694 platform/chrome: cros_typec_switch: Add missing fwnode_handle_put()
In reply to Greg Kroah-HartmanFrom: Liang He <[email protected]>
[ Upstream commit dc70234c408c644505a24362b0f095f713e4697e ]
In cros_typec_register_switches(), we should add fwnode_handle_put() when break out of the iteration device_for_each_child_node() as it will automatically increase and decrease the refcounter.
--- drivers/platform/chrome/cros_typec_switch.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/chrome/cros_typec_switch.c +1 -0
@@ -270,6 +270,7 @@ static int cros_typec_register_switches(struct cros_typec_switch_data *sdata)return 0 ; err_switch: +fwnode_handle_put (fwnode);cros_typec_unregister_switches (sdata);return ret; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 321/694 media: ov5670: Fix probe on ACPI
In reply to Greg Kroah-HartmanFrom: Sakari Ailus <[email protected]>
[ Upstream commit 73b41dc51fbeffa4a216b20193274cfe92b5d95b ]
devm_clk_get() will return either an error or NULL, which the driver handles, continuing to use the clock of reading the value of the clock-frequency property.
However, the value of ov5670->xvclk is left as-is and the other clock framework functions aren't capable of handling error values.
Use devm_clk_get_optional() to obtain NULL instead of -ENOENT.
--- drivers/media/i2c/ov5670.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5670.c +1 -1
@@ -2660,7 +2660,7 @@ static int ov5670_probe(struct i2c_client *client) goto error_print; } - ov5670->xvclk =devm_clk_get (&client->dev,NULL ); + ov5670->xvclk =devm_clk_get_optional (&client->dev,NULL );if (!IS_ERR_OR_NULL (ov5670->xvclk)) input_clk =clk_get_rate (ov5670->xvclk);else if (PTR_ERR (ov5670->xvclk) == -ENOENT )
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 322/694 wifi: ath6kl: minor fix for allocation size
In reply to Greg Kroah-HartmanFrom: Alexey V. Vissarionov <[email protected]>
[ Upstream commit 778f83f889e7fca37780d9640fcbd0229ae38eaa ]
Although the "param" pointer occupies more or equal space compared to "*param", the allocation size should use the size of variable itself.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/net/wireless/ath/ath6kl/bmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath6kl/bmi.c +1 -1
@@ -246,7 +246,7 @@ int ath6kl_bmi_execute(struct ath6kl *ar, u32 addr, u32 *param)return -EACCES ; } - size =sizeof (cid) +sizeof (addr) +sizeof (param); + size =sizeof (cid) +sizeof (addr) +sizeof (*param);if (size > ar->bmi.max_cmd_size) {WARN_ON (1 );return -EINVAL ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 323/694 wifi: ath12k: use kfree_skb() instead of kfree()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
[ Upstream commit 8c464d16809fa02982f6341ea598ec5d07457f19 ]
Sk_buffs are supposed to be freed with kfree_skb().
--- drivers/net/wireless/ath/ath12k/dp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/dp_tx.c +1 -1
@@ -270,7 +270,7 @@ int ath12k_dp_tx(struct ath12k *ar, struct ath12k_vif *arvif, skb_ext_desc->len, DMA_TO_DEVICE); ret =dma_mapping_error (ab->dev, ti.paddr);if (ret) { -kfree (skb_ext_desc); +kfree_skb (skb_ext_desc); goto fail_unmap_dma; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 324/694 wifi: ath11k: fix return value check in ath11k_ahb_probe()
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
[ Upstream commit 342fcde9d91460f01f65707e16368a1571271a3a ]
ioremap() returns NULL pointer not PTR_ERR() when it fails, so replace the IS_ERR() check with NULL pointer check.
--- drivers/net/wireless/ath/ath11k/ahb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/ahb.c +1 -1
@@ -1174,7 +1174,7 @@ static int ath11k_ahb_probe(struct platform_device *pdev)* to a new space for accessing them. */ ab->mem_ce =ioremap (ce_remap->base, ce_remap->size); -if (IS_ERR (ab->mem_ce)) { +if (!ab->mem_ce) {dev_err (&pdev->dev,"ce ioremap error\n" ); ret = -ENOMEM ; goto err_core_free;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 325/694 wifi: ath9k: hif_usb: fix memory leak of remain_skbs
In reply to Greg Kroah-HartmanFrom: Fedor Pchelkin <[email protected]>
[ Upstream commit 7654cc03eb699297130b693ec34e25f77b17c947 ]
hif_dev->remain_skb is allocated and used exclusively in ath9k_hif_usb_rx_stream(). It is implied that an allocated remain_skb is processed and subsequently freed (in error paths) only during the next call of ath9k_hif_usb_rx_stream().
So, if the urbs are deallocated between those two calls due to the device deinitialization or suspend, it is possible that ath9k_hif_usb_rx_stream() is not called next time and the allocated remain_skb is leaked. Our local Syzkaller instance was able to trigger that.
remain_skb makes sense when receiving two consecutive urbs which are logically linked together, i.e. a specific data field from the first skb indicates a cached skb to be allocated, memcpy'd with some data and subsequently processed in the next call to ath9k_hif_usb_rx_stream(). Urbs deallocation supposedly makes that link irrelevant so we need to free the cached skb in those cases.
Fix the leak by introducing a function to explicitly free remain_skb (if it is not NULL) when the rx urbs have been deallocated. remain_skb is NULL when it has not been allocated at all (hif_dev struct is kzalloced) or when it has been processed in next call to ath9k_hif_usb_rx_stream().
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- drivers/net/wireless/ath/ath9k/hif_usb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +19 -0
@@ -534,6 +534,24 @@ static struct ath9k_htc_hif hif_usb = { .send = hif_usb_send, }; +/* Need to free remain_skb allocated in ath9k_hif_usb_rx_stream +* in case ath9k_hif_usb_rx_stream wasn't called next time to +* process the buffer and subsequently free it. +*/ +static void ath9k_hif_usb_free_rx_remain_skb (struct hif_device_usb *hif_dev) +{ +unsigned long flags; + +spin_lock_irqsave (&hif_dev->rx_lock, flags); +if (hif_dev->remain_skb) { +dev_kfree_skb_any (hif_dev->remain_skb); + hif_dev->remain_skb =NULL ; + hif_dev->rx_remain_len =0 ; +RX_STAT_INC (hif_dev, skb_dropped); + } +spin_unlock_irqrestore (&hif_dev->rx_lock, flags); +} +static void ath9k_hif_usb_rx_stream (struct hif_device_usb *hif_dev,struct sk_buff *skb) {
@@ -868,6 +886,7 @@ static int ath9k_hif_usb_alloc_tx_urbs(struct hif_device_usb *hif_dev)static void ath9k_hif_usb_dealloc_rx_urbs (struct hif_device_usb *hif_dev) {usb_kill_anchored_urbs (&hif_dev->rx_submitted); +ath9k_hif_usb_free_rx_remain_skb (hif_dev); }static int ath9k_hif_usb_alloc_rx_urbs (struct hif_device_usb *hif_dev)
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 326/694 wifi: ath11k: Use platform_get_irq() to get the interrupt
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit f117276638b7600b981b3fe28550823cfbe1ef23 ]
As of commit a1a2b7125e10 ("of/platform: Drop static setup of IRQ resource from DT core"), we need to use platform_get_irq() instead of platform_get_resource() to get our IRQs because platform_get_resource() simply won't get them anymore.
This was already fixed in several other Atheros WiFi drivers, apparently in response to Zeal Robot reports. An example of another fix is commit 9503a1fc123d ("ath9k: Use platform_get_irq() to get the interrupt"). ath11k seems to have been missed in this effort, though.
Without this change, WiFi wasn't coming up on my Qualcomm sc7280-based hardware. Specifically, "platform_get_resource(pdev, IORESOURCE_IRQ, i)" was failing even for i=0.
Tested-on: WCN6750 hw1.0 AHB WLAN.MSL.1.0.1-00887-QCAMSLSWPLZ-1
--- drivers/net/wireless/ath/ath11k/ahb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath11k/ahb.c +4 -4
@@ -874,11 +874,11 @@ static int ath11k_ahb_setup_msi_resources(struct ath11k_base *ab) ab->pci.msi.ep_base_data = int_prop +32 ;for (i =0 ; i < ab->pci.msi.config->total_vectors; i++) { - res =platform_get_resource (pdev,IORESOURCE_IRQ , i); -if (!res) -return -ENODEV ; + ret =platform_get_irq (pdev, i); +if (ret <0 ) +return ret; - ab->pci.msi.irqs[i] = res->start; + ab->pci.msi.irqs[i] = ret; }set_bit (ATH11K_FLAG_MULTI_MSI_VECTORS , &ab->dev_flags);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 327/694 wifi: ath5k: Use platform_get_irq() to get the interrupt
In reply to Greg Kroah-HartmanFrom: Douglas Anderson <[email protected]>
[ Upstream commit 95c95251d0547b46d6571e4fbd51b42865c15a4a ]
As of commit a1a2b7125e10 ("of/platform: Drop static setup of IRQ resource from DT core"), we need to use platform_get_irq() instead of platform_get_resource() to get our IRQs because platform_get_resource() simply won't get them anymore.
This was already fixed in several other Atheros WiFi drivers, apparently in response to Zeal Robot reports. An example of another fix is commit 9503a1fc123d ("ath9k: Use platform_get_irq() to get the interrupt"). ath5k seems to have been missed in this effort, though.
--- drivers/net/wireless/ath/ath5k/ahb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath5k/ahb.c +4 -6
@@ -113,15 +113,13 @@ static int ath_ahb_probe(struct platform_device *pdev) goto err_out; } - res =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); -if (res ==NULL ) { -dev_err (&pdev->dev,"no IRQ resource found\n" ); - ret = -ENXIO ; + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (&pdev->dev,"no IRQ resource found: %d\n" , irq); + ret = irq; goto err_iounmap; } - irq = res->start; - hw =ieee80211_alloc_hw (sizeof (struct ath5k_hw ), &ath5k_hw_ops);if (hw ==NULL ) {dev_err (&pdev->dev,"no memory for ieee80211_hw\n" );
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 328/694 wifi: ath5k: fix an off by one check in ath5k_eeprom_read_freq_list()
In reply to Greg Kroah-HartmanFrom: Dan Carpenter <[email protected]>
[ Upstream commit 4c856ee12df85aabd437c3836ed9f68d94268358 ]
This loop checks that i < max at the start of loop but then it does i++ which could put it past the end of the array. It's harmless to check again and prevent a potential out of bounds.
--- drivers/net/wireless/ath/ath5k/eeprom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath5k/eeprom.c +1 -1
@@ -529,7 +529,7 @@ ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max, ee->ee_n_piers[mode]++; freq2 = (val >>8 ) &0xff ; -if (!freq2) +if (!freq2 || i >= max)break ; pc[i++].freq = ath5k_eeprom_bin2freq(ee,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 329/694 wifi: ath11k: fix SAC bug on peer addition with sta band migration
In reply to Greg Kroah-HartmanFrom: Christian Marangi <[email protected]>
[ Upstream commit 60b7d62ba8cdbd073997bff0f1cdae8d844002c0 ]
Fix sleep in atomic context warning detected by Smatch static checker analyzer.
Following the locking pattern for peer_rhash_add lock tbl_mtx_lock mutex always even if sta is not transitioning to another band. This is peer_add function and a more secure locking should not cause performance regression.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.5.0.1-01208-QCAHKSWPL_SILICONZ-1
--- drivers/net/wireless/ath/ath11k/peer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/peer.c +3 -2
@@ -382,22 +382,23 @@ int ath11k_peer_create(struct ath11k *ar, struct ath11k_vif *arvif,return -ENOBUFS ; } +mutex_lock (&ar->ab->tbl_mtx_lock);spin_lock_bh (&ar->ab->base_lock); peer =ath11k_peer_find_by_addr (ar->ab, param->peer_addr);if (peer) {if (peer->vdev_id == param->vdev_id) {spin_unlock_bh (&ar->ab->base_lock); +mutex_unlock (&ar->ab->tbl_mtx_lock);return -EINVAL ; }/* Assume sta is transitioning to another band. * Remove here the peer from rhash. */ -mutex_lock (&ar->ab->tbl_mtx_lock);ath11k_peer_rhash_delete (ar->ab, peer); -mutex_unlock (&ar->ab->tbl_mtx_lock); }spin_unlock_bh (&ar->ab->base_lock); +mutex_unlock (&ar->ab->tbl_mtx_lock); ret =ath11k_wmi_send_peer_create_cmd (ar, param);if (ret) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 330/694 wifi: rtl8xxxu: Remove always true condition in rtl8xxxu_print_chipinfo
In reply to Greg Kroah-HartmanFrom: Bitterblue Smith <[email protected]>
[ Upstream commit b9b1e4fe2957f361c86e288ecf373dc7895cf7c7 ]
Fix a new smatch warning:drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c:1580 rtl8xxxu_print_chipinfo() warn: always true condition '(priv->chip_cut <= 15) => (0-15 <= 15)'
--- drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c +1 -5
@@ -1575,11 +1575,7 @@ rtl8xxxu_set_spec_sifs(struct rtl8xxxu_priv *priv, u16 cck, u16 ofdm)static void rtl8xxxu_print_chipinfo (struct rtl8xxxu_priv *priv) {struct device *dev = &priv->udev->dev; -char cut ='?' ; - -/* Currently always true: chip_cut is 4 bits. */ -if (priv->chip_cut <=15 ) - cut ='A' + priv->chip_cut; +char cut ='A' + priv->chip_cut; dev_info(dev, "RTL%s rev %c (%s) romver %d, %iT%iR, TX queues %i, WiFi=%i, BT=%i, GPS=%i, HI PA=%i\n",
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 331/694 wifi: brcmfmac: support CQM RSSI notification with older firmware
In reply to Greg Kroah-HartmanFrom: John Keeping <[email protected]>
[ Upstream commit ec52d77d077529f198fd874c550a26b9cc86a331 ]
Using the BCM4339 firmware from linux-firmware (version "BCM4339/2 wl0:
Sep 5 2019 11:05:52 version 6.37.39.113 (r722271 CY)" from cypress/cyfmac4339-sdio.bin) the RSSI respose is only 4 bytes, which results in an error being logged.
It seems that older devices send only the RSSI field and neither SNR nor noise is included. Handle this by accepting a 4 byte message and reading only the RSSI from it.
--- .../broadcom/brcm80211/brcmfmac/cfg80211.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c +8 -6
@@ -6494,18 +6494,20 @@ static s32 brcmf_notify_rssi(struct brcmf_if *ifp, {struct brcmf_cfg80211_vif *vif = ifp->vif;struct brcmf_rssi_be *info = data; -s32 rssi, snr, noise; +s32 rssi, snr =0 , noise =0 ;s32 low, high, last; -if (e->datalen <sizeof (*info)) { +if (e->datalen >=sizeof (*info)) { + rssi =be32_to_cpu (info->rssi); + snr =be32_to_cpu (info->snr); + noise =be32_to_cpu (info->noise); + }else if (e->datalen >=sizeof (rssi)) { + rssi =be32_to_cpu (*(__be32 *)data); + }else {brcmf_err ("insufficient RSSI event data\n" );return 0 ; } - rssi =be32_to_cpu (info->rssi); - snr =be32_to_cpu (info->snr); - noise =be32_to_cpu (info->noise); - low = vif->cqm_rssi_low; high = vif->cqm_rssi_high; last = vif->cqm_rssi_last;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 332/694 wifi: ath6kl: reduce WARN to dev_dbg() in callback
In reply to Greg Kroah-HartmanFrom: Fedor Pchelkin <[email protected]>
[ Upstream commit 75c4a8154cb6c7239fb55d5550f481f6765fb83c ]
The warn is triggered on a known race condition, documented in the code above the test, that is correctly handled. Using WARN() hinders automated testing. Reducing severity.
--- drivers/net/wireless/ath/ath6kl/htc_pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath6kl/htc_pipe.c +2 -2
@@ -960,8 +960,8 @@ static int ath6kl_htc_pipe_rx_complete(struct ath6kl *ar, struct sk_buff *skb,* Thus the possibility of ar->htc_target being NULL * via ath6kl_recv_complete -> ath6kl_usb_io_comp_work. */ -if (WARN_ON_ONCE (!target)) { -ath6kl_err ("Target not yet initialized\n" ); +if (!target) { +ath6kl_dbg (ATH6KL_DBG_HTC ,"Target not yet initialized\n" ); status = -EINVAL ; goto free_skb; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 333/694 tools: bpftool: Remove invalid \ json escape
In reply to Greg Kroah-HartmanFrom: Luis Gerhorst <[email protected]>
[ Upstream commit c679bbd611c08b0559ffae079330bc4e5574696a ]
RFC8259 ("The JavaScript Object Notation (JSON) Data Interchange Format") only specifies \", \\, \/, \b, \f, \n, \r, and \r as valid two-character escape sequences. This does not include \', which is not required in JSON because it exclusively uses double quotes as string separators.
Solidus (/) may be escaped, but does not have to. Only reverse solidus (\), double quotes ("), and the control characters have to be escaped. Therefore, with this fix, bpftool correctly supports all valid two-character escape sequences (but still does not support characters that require multi-character escape sequences).
Witout this fix, attempting to load a JSON file generated by bpftool using Python 3.10.6's default json.load() may fail with the error "Invalid \escape" if the file contains the invalid escaped single quote (\').
--- tools/bpf/bpftool/json_writer.c | 3 --- 1 file changed, 3 deletions(-)
tools/bpf/bpftool/json_writer.c +0 -3
@@ -80,9 +80,6 @@ static void jsonw_puts(json_writer_t *self, const char *str)case '"' :fputs ("\\\"" , self->out);break ; -case '\'' : -fputs ("\\\'" , self->out); -break ;default :putc (*str, self->out); }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 334/694 libbpf: Fix arm syscall regs spec in bpf_tracing.h
In reply to Greg Kroah-HartmanFrom: Puranjay Mohan <[email protected]>
[ Upstream commit 06943ae675945c762bb8d5edc93d203f2b041d8d ]
The syscall register definitions for ARM in bpf_tracing.h doesn't define the fifth parameter for the syscalls. Because of this some KPROBES based selftests fail to compile for ARM architecture.
Define the fifth parameter that is passed in the R5 register (uregs[4]).
--- tools/lib/bpf/bpf_tracing.h | 1 + 1 file changed, 1 insertion(+)
tools/lib/bpf/bpf_tracing.h +1 -0
@@ -204,6 +204,7 @@ struct pt_regs___s390 {#define __PT_PARM2_SYSCALL_REG __PT_PARM2_REG#define __PT_PARM3_SYSCALL_REG __PT_PARM3_REG#define __PT_PARM4_SYSCALL_REG __PT_PARM4_REG +#define __PT_PARM5_SYSCALL_REG uregs[4]#define __PT_PARM6_SYSCALL_REG uregs[5]#define __PT_PARM7_SYSCALL_REG uregs[6]
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 335/694 libbpf: Fix bpf_xdp_query() in old kernels
In reply to Greg Kroah-HartmanFrom: Yonghong Song <[email protected]>
[ Upstream commit c8ee37bde4021a275d2e4f33bd48d54912bb00c4 ]
Commit 04d58f1b26a4("libbpf: add API to get XDP/XSK supported features") added feature_flags to struct bpf_xdp_query_opts. If a user uses bpf_xdp_query_opts with feature_flags member, the bpf_xdp_query() will check whether 'netdev' family exists or not in the kernel. If it does not exist, the bpf_xdp_query() will return -ENOENT.
But 'netdev' family does not exist in old kernels as it is introduced in the same patch set as Commit 04d58f1b26a4. So old kernel with newer libbpf won't work properly with bpf_xdp_query() api call.
To fix this issue, if the return value of libbpf_netlink_resolve_genl_family_id() is -ENOENT, bpf_xdp_query() will just return 0, skipping the rest of xdp feature query. This preserves backward compatibility.
--- tools/lib/bpf/netlink.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tools/lib/bpf/netlink.c +7 -1
@@ -468,8 +468,13 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts)return 0 ; err =libbpf_netlink_resolve_genl_family_id ("netdev" ,sizeof ("netdev" ), &id); -if (err <0 ) +if (err <0 ) { +if (err == -ENOENT ) { + opts->feature_flags =0 ; + goto skip_feature_flags; + }return libbpf_err (err); + }memset (&req,0 ,sizeof (req)); req.nh.nlmsg_len =NLMSG_LENGTH (GENL_HDRLEN );
@@ -489,6 +494,7 @@ int bpf_xdp_query(int ifindex, int xdp_flags, struct bpf_xdp_query_opts *opts) opts->feature_flags = md.flags; +skip_feature_flags:return 0 ; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 336/694 wifi: rtw88: mac: Return the original error from rtw_pwr_seq_parser()
In reply to Greg Kroah-HartmanFrom: Martin Blumenstingl <[email protected]>
[ Upstream commit b7ed9fa2cb76ca7a3c3cd4a6d35748fe1fbda9f6 ]
rtw_pwr_seq_parser() calls rtw_sub_pwr_seq_parser() which can either return -EBUSY, -EINVAL or 0. Propagate the original error code instead of unconditionally returning -EBUSY in case of an error.
--- drivers/net/wireless/realtek/rtw88/mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/mac.c +1 -1
@@ -233,7 +233,7 @@ static int rtw_pwr_seq_parser(struct rtw_dev *rtwdev, ret =rtw_sub_pwr_seq_parser (rtwdev, intf_mask, cut_mask, cmd);if (ret) -return -EBUSY ; +return ret; idx++; }while (1 );
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 337/694 wifi: rtw88: mac: Return the original error from rtw_mac_power_switch()
In reply to Greg Kroah-HartmanFrom: Martin Blumenstingl <[email protected]>
[ Upstream commit 15c8e267dfa62f207ee1db666c822324e3362b84 ]
rtw_mac_power_switch() calls rtw_pwr_seq_parser() which can return -EINVAL, -EBUSY or 0. Propagate the original error code instead of unconditionally returning -EINVAL in case of an error.
--- drivers/net/wireless/realtek/rtw88/mac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw88/mac.c +4 -2
@@ -247,6 +247,7 @@ static int rtw_mac_power_switch(struct rtw_dev *rtwdev, bool pwr_on)const struct rtw_pwr_seq_cmd **pwr_seq;u8 rpwm;bool cur_pwr; +int ret;if (rtw_chip_wcpu_11ac (rtwdev)) { rpwm =rtw_read8 (rtwdev, rtwdev->hci.rpwm_addr);
@@ -270,8 +271,9 @@ static int rtw_mac_power_switch(struct rtw_dev *rtwdev, bool pwr_on)return -EALREADY ; pwr_seq = pwr_on ? chip->pwr_on_seq : chip->pwr_off_seq; -if (rtw_pwr_seq_parser (rtwdev, pwr_seq)) -return -EINVAL ; + ret =rtw_pwr_seq_parser (rtwdev, pwr_seq); +if (ret) +return ret;if (pwr_on)set_bit (RTW_FLAG_POWERON , rtwdev->flags);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 338/694 selftests/bpf: Fix IMA test
In reply to Greg Kroah-HartmanFrom: Roberto Sassu <[email protected]>
[ Upstream commit 12fabae03ca6474fd571bf6ddb37d009533305d6 ]
Commit 62622dab0a28 ("ima: return IMA digest value only when IMA_COLLECTED flag is set") caused bpf_ima_inode_hash() to refuse to give non-fresh digests. IMA test #3 assumed the old behavior, that bpf_ima_inode_hash() still returned also non-fresh digests.
Correct the test by accepting both cases. If the samples returned are 1, assume that the commit above is applied and that the returned digest is fresh. If the samples returned are 2, assume that the commit above is not applied, and check both the non-fresh and fresh digest.
--- .../selftests/bpf/prog_tests/test_ima.c | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_ima.c +21 -8
@@ -70,7 +70,7 @@ void test_test_ima(void)u64 bin_true_sample;char cmd[256 ]; -int err, duration =0 ; +int err, duration =0 , fresh_digest_idx =0 ;struct ima *skel =NULL ; skel =ima__open_and_load ();
@@ -129,7 +129,15 @@ void test_test_ima(void)/* * Test #3 * - Goal: confirm that bpf_ima_inode_hash() returns a non-fresh digest -* - Expected result: 2 samples (/bin/true: non-fresh, fresh) +* - Expected result: +* 1 sample (/bin/true: fresh) if commit 62622dab0a28 applied +* 2 samples (/bin/true: non-fresh, fresh) if commit 62622dab0a28 is +* not applied +* +* If commit 62622dab0a28 ("ima: return IMA digest value only when +* IMA_COLLECTED flag is set") is applied, bpf_ima_inode_hash() refuses +* to give a non-fresh digest, hence the correct result is 1 instead of +* 2. */ test_init (skel->bss);
@@ -144,13 +152,18 @@ void test_test_ima(void) goto close_clean; err =ring_buffer__consume (ringbuf); -ASSERT_EQ (err,2 ,"num_samples_or_err" ); -ASSERT_NEQ (ima_hash_from_bpf[0 ],0 ,"ima_hash" ); -ASSERT_NEQ (ima_hash_from_bpf[1 ],0 ,"ima_hash" ); -ASSERT_EQ (ima_hash_from_bpf[0 ], bin_true_sample,"sample_equal_or_err" ); +ASSERT_GE (err,1 ,"num_samples_or_err" ); +if (err ==2 ) { +ASSERT_NEQ (ima_hash_from_bpf[0 ],0 ,"ima_hash" ); +ASSERT_EQ (ima_hash_from_bpf[0 ], bin_true_sample, +"sample_equal_or_err" ); + fresh_digest_idx =1 ; + } + +ASSERT_NEQ (ima_hash_from_bpf[fresh_digest_idx],0 ,"ima_hash" );/* IMA refreshed the digest. */ -ASSERT_NEQ (ima_hash_from_bpf[1 ], bin_true_sample, -"sample_different_or_err" ); +ASSERT_NEQ (ima_hash_from_bpf[fresh_digest_idx], bin_true_sample, +"sample_equal_or_err" );/* * Test #4
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 339/694 selftests/bpf: move SYS() macro into the test_progs.h
In reply to Greg Kroah-HartmanFrom: Hangbin Liu <[email protected]>
[ Upstream commit b61987d37cbee3c44e80304598c60b163553926b ]
A lot of tests defined SYS() macro to run system calls with goto label. Let's move this macro to test_progs.h and add configurable "goto_label" as the first arg.
Stable-dep-of: a6865576317f ("selftests/bpf: Fix flaky fib_lookup test")
--- .../selftests/bpf/prog_tests/decap_sanity.c | 16 +-- .../selftests/bpf/prog_tests/empty_skb.c | 25 ++--- .../selftests/bpf/prog_tests/fib_lookup.c | 28 ++--- .../selftests/bpf/prog_tests/tc_redirect.c | 100 ++++++++---------- .../selftests/bpf/prog_tests/test_tunnel.c | 71 +++++-------- .../selftests/bpf/prog_tests/xdp_bonding.c | 40 +++---- .../bpf/prog_tests/xdp_do_redirect.c | 30 ++---- .../selftests/bpf/prog_tests/xdp_metadata.c | 23 ++-- .../selftests/bpf/prog_tests/xdp_synproxy.c | 41 ++++--- .../selftests/bpf/prog_tests/xfrm_info.c | 67 +++++------- tools/testing/selftests/bpf/test_progs.h | 15 +++ 11 files changed, 193 insertions(+), 263 deletions(-)
tools/testing/selftests/bpf/prog_tests/decap_sanity.c +4 -12
@@ -10,14 +10,6 @@#include "network_helpers.h" #include "decap_sanity.skel.h" -#define SYS (fmt, ...) \ - ({ \ - char cmd[1024]; \ - snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ - if (!ASSERT_OK(system(cmd), cmd)) \ - goto fail; \ - }) -#define NS_TEST "decap_sanity_ns"#define IPV6_IFACE_ADDR "face::1"#define UDP_TEST_PORT 7777
@@ -37,9 +29,9 @@ void test_decap_sanity(void)if (!ASSERT_OK_PTR (skel,"skel open_and_load" ))return ; -SYS ("ip netns add %s" ,NS_TEST ); -SYS ("ip -net %s -6 addr add %s/128 dev lo nodad" ,NS_TEST ,IPV6_IFACE_ADDR ); -SYS ("ip -net %s link set dev lo up" ,NS_TEST ); +SYS (fail,"ip netns add %s" ,NS_TEST ); +SYS (fail,"ip -net %s -6 addr add %s/128 dev lo nodad" ,NS_TEST ,IPV6_IFACE_ADDR ); +SYS (fail,"ip -net %s link set dev lo up" ,NS_TEST ); nstoken =open_netns (NS_TEST );if (!ASSERT_OK_PTR (nstoken,"open_netns" ))
@@ -80,6 +72,6 @@ void test_decap_sanity(void)bpf_tc_hook_destroy (&qdisc_hook);close_netns (nstoken); } -system ("ip netns del " NS_TEST " &> /dev/null" ); +SYS_NOFAIL ("ip netns del " NS_TEST " &> /dev/null" );decap_sanity__destroy (skel); }
tools/testing/selftests/bpf/prog_tests/empty_skb.c +10 -15
@@ -4,11 +4,6 @@#include <net/if.h> #include "empty_skb.skel.h" -#define SYS (cmd) ({ \ - if (!ASSERT_OK(system(cmd), (cmd))) \ - goto out; \ -}) -void test_empty_skb (void ) {LIBBPF_OPTS (bpf_test_run_opts, tattr);
@@ -93,18 +88,18 @@ void test_empty_skb(void) }, }; -SYS ("ip netns add empty_skb" ); +SYS (out,"ip netns add empty_skb" ); tok =open_netns ("empty_skb" ); -SYS ("ip link add veth0 type veth peer veth1" ); -SYS ("ip link set dev veth0 up" ); -SYS ("ip link set dev veth1 up" ); -SYS ("ip addr add 10.0.0.1/8 dev veth0" ); -SYS ("ip addr add 10.0.0.2/8 dev veth1" ); +SYS (out,"ip link add veth0 type veth peer veth1" ); +SYS (out,"ip link set dev veth0 up" ); +SYS (out,"ip link set dev veth1 up" ); +SYS (out,"ip addr add 10.0.0.1/8 dev veth0" ); +SYS (out,"ip addr add 10.0.0.2/8 dev veth1" ); veth_ifindex =if_nametoindex ("veth0" ); -SYS ("ip link add ipip0 type ipip local 10.0.0.1 remote 10.0.0.2" ); -SYS ("ip link set ipip0 up" ); -SYS ("ip addr add 192.168.1.1/16 dev ipip0" ); +SYS (out,"ip link add ipip0 type ipip local 10.0.0.1 remote 10.0.0.2" ); +SYS (out,"ip link set ipip0 up" ); +SYS (out,"ip addr add 192.168.1.1/16 dev ipip0" ); ipip_ifindex =if_nametoindex ("ipip0" ); bpf_obj =empty_skb__open_and_load ();
@@ -142,5 +137,5 @@ void test_empty_skb(void)empty_skb__destroy (bpf_obj);if (tok)close_netns (tok); -system ("ip netns del empty_skb" ); +SYS_NOFAIL ("ip netns del empty_skb" ); }
tools/testing/selftests/bpf/prog_tests/fib_lookup.c +10 -18
@@ -8,14 +8,6 @@#include "network_helpers.h" #include "fib_lookup.skel.h" -#define SYS (fmt, ...) \ - ({ \ - char cmd[1024]; \ - snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ - if (!ASSERT_OK(system(cmd), cmd)) \ - goto fail; \ - }) -#define NS_TEST "fib_lookup_ns"#define IPV6_IFACE_ADDR "face::face"#define IPV6_NUD_FAILED_ADDR "face::1"
@@ -59,16 +51,16 @@ static int setup_netns(void) {int err; -SYS ("ip link add veth1 type veth peer name veth2" ); -SYS ("ip link set dev veth1 up" ); +SYS (fail,"ip link add veth1 type veth peer name veth2" ); +SYS (fail,"ip link set dev veth1 up" ); -SYS ("ip addr add %s/64 dev veth1 nodad" ,IPV6_IFACE_ADDR ); -SYS ("ip neigh add %s dev veth1 nud failed" ,IPV6_NUD_FAILED_ADDR ); -SYS ("ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV6_NUD_STALE_ADDR ,DMAC ); +SYS (fail,"ip addr add %s/64 dev veth1 nodad" ,IPV6_IFACE_ADDR ); +SYS (fail,"ip neigh add %s dev veth1 nud failed" ,IPV6_NUD_FAILED_ADDR ); +SYS (fail,"ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV6_NUD_STALE_ADDR ,DMAC ); -SYS ("ip addr add %s/24 dev veth1 nodad" ,IPV4_IFACE_ADDR ); -SYS ("ip neigh add %s dev veth1 nud failed" ,IPV4_NUD_FAILED_ADDR ); -SYS ("ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV4_NUD_STALE_ADDR ,DMAC ); +SYS (fail,"ip addr add %s/24 dev veth1 nodad" ,IPV4_IFACE_ADDR ); +SYS (fail,"ip neigh add %s dev veth1 nud failed" ,IPV4_NUD_FAILED_ADDR ); +SYS (fail,"ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV4_NUD_STALE_ADDR ,DMAC ); err =write_sysctl ("/proc/sys/net/ipv4/conf/veth1/forwarding" ,"1" );if (!ASSERT_OK (err,"write_sysctl(net.ipv4.conf.veth1.forwarding)" ))
@@ -140,7 +132,7 @@ void test_fib_lookup(void)return ; prog_fd =bpf_program__fd (skel->progs.fib_lookup); -SYS ("ip netns add %s" ,NS_TEST ); +SYS (fail,"ip netns add %s" ,NS_TEST ); nstoken =open_netns (NS_TEST );if (!ASSERT_OK_PTR (nstoken,"open_netns" ))
@@ -182,6 +174,6 @@ void test_fib_lookup(void) fail:if (nstoken)close_netns (nstoken); -system ("ip netns del " NS_TEST " &> /dev/null" ); +SYS_NOFAIL ("ip netns del " NS_TEST " &> /dev/null" );fib_lookup__destroy (skel); }
tools/testing/selftests/bpf/prog_tests/tc_redirect.c +46 -54
165 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +28 -43
114 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/xdp_bonding.c +16 -24
@@ -141,41 +141,33 @@ static const char * const xmit_policy_names[] = {static int bonding_setup (struct skeletons *skeletons,int mode,int xmit_policy,int bond_both_attach) { -#define SYS (fmt, ...) \ - ({ \ - char cmd[1024]; \ - snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ - if (!ASSERT_OK(system(cmd), cmd)) \ - return -1; \ - }) - -SYS ("ip netns add ns_dst" ); -SYS ("ip link add veth1_1 type veth peer name veth2_1 netns ns_dst" ); -SYS ("ip link add veth1_2 type veth peer name veth2_2 netns ns_dst" ); - -SYS ("ip link add bond1 type bond mode %s xmit_hash_policy %s" , +SYS (fail,"ip netns add ns_dst" ); +SYS (fail,"ip link add veth1_1 type veth peer name veth2_1 netns ns_dst" ); +SYS (fail,"ip link add veth1_2 type veth peer name veth2_2 netns ns_dst" ); + +SYS (fail,"ip link add bond1 type bond mode %s xmit_hash_policy %s" , mode_names[mode], xmit_policy_names[xmit_policy]); -SYS ("ip link set bond1 up address " BOND1_MAC_STR " addrgenmode none" ); -SYS ("ip -netns ns_dst link add bond2 type bond mode %s xmit_hash_policy %s" , +SYS (fail,"ip link set bond1 up address " BOND1_MAC_STR " addrgenmode none" ); +SYS (fail,"ip -netns ns_dst link add bond2 type bond mode %s xmit_hash_policy %s" , mode_names[mode], xmit_policy_names[xmit_policy]); -SYS ("ip -netns ns_dst link set bond2 up address " BOND2_MAC_STR " addrgenmode none" ); +SYS (fail,"ip -netns ns_dst link set bond2 up address " BOND2_MAC_STR " addrgenmode none" ); -SYS ("ip link set veth1_1 master bond1" ); +SYS (fail,"ip link set veth1_1 master bond1" );if (bond_both_attach ==BOND_BOTH_AND_ATTACH ) { -SYS ("ip link set veth1_2 master bond1" ); +SYS (fail,"ip link set veth1_2 master bond1" ); }else { -SYS ("ip link set veth1_2 up addrgenmode none" ); +SYS (fail,"ip link set veth1_2 up addrgenmode none" );if (xdp_attach (skeletons, skeletons->xdp_dummy->progs.xdp_dummy_prog,"veth1_2" ))return -1 ; } -SYS ("ip -netns ns_dst link set veth2_1 master bond2" ); +SYS (fail,"ip -netns ns_dst link set veth2_1 master bond2" );if (bond_both_attach ==BOND_BOTH_AND_ATTACH ) -SYS ("ip -netns ns_dst link set veth2_2 master bond2" ); +SYS (fail,"ip -netns ns_dst link set veth2_2 master bond2" );else -SYS ("ip -netns ns_dst link set veth2_2 up addrgenmode none" ); +SYS (fail,"ip -netns ns_dst link set veth2_2 up addrgenmode none" );/* Load a dummy program on sending side as with veth peer needs to have a * XDP program loaded as well.
@@ -194,8 +186,8 @@ static int bonding_setup(struct skeletons *skeletons, int mode, int xmit_policy, }return 0 ; - -#undef SYS +fail: +return -1 ; }static void bonding_cleanup (struct skeletons *skeletons)
tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c +11 -19
@@ -12,14 +12,6 @@#include <uapi/linux/netdev.h> #include "test_xdp_do_redirect.skel.h" -#define SYS (fmt, ...) \ - ({ \ - char cmd[1024]; \ - snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ - if (!ASSERT_OK(system(cmd), cmd)) \ - goto out; \ - }) -struct udp_packet {struct ethhdr eth;struct ipv6hdr iph;
@@ -127,19 +119,19 @@ void test_xdp_do_redirect(void)* iface and NUM_PKTS-2 in the TC hook. We match the packets on the UDP * payload. */ -SYS ("ip netns add testns" ); +SYS (out,"ip netns add testns" ); nstoken =open_netns ("testns" );if (!ASSERT_OK_PTR (nstoken,"setns" )) goto out; -SYS ("ip link add veth_src type veth peer name veth_dst" ); -SYS ("ip link set dev veth_src address 00:11:22:33:44:55" ); -SYS ("ip link set dev veth_dst address 66:77:88:99:aa:bb" ); -SYS ("ip link set dev veth_src up" ); -SYS ("ip link set dev veth_dst up" ); -SYS ("ip addr add dev veth_src fc00::1/64" ); -SYS ("ip addr add dev veth_dst fc00::2/64" ); -SYS ("ip neigh add fc00::2 dev veth_src lladdr 66:77:88:99:aa:bb" ); +SYS (out,"ip link add veth_src type veth peer name veth_dst" ); +SYS (out,"ip link set dev veth_src address 00:11:22:33:44:55" ); +SYS (out,"ip link set dev veth_dst address 66:77:88:99:aa:bb" ); +SYS (out,"ip link set dev veth_src up" ); +SYS (out,"ip link set dev veth_dst up" ); +SYS (out,"ip addr add dev veth_src fc00::1/64" ); +SYS (out,"ip addr add dev veth_dst fc00::2/64" ); +SYS (out,"ip neigh add fc00::2 dev veth_src lladdr 66:77:88:99:aa:bb" );/* We enable forwarding in the test namespace because that will cause * the packets that go through the kernel stack (with XDP_PASS) to be
@@ -152,7 +144,7 @@ void test_xdp_do_redirect(void)* code didn't have this, so we keep the test behaviour to make sure the * bug doesn't resurface. */ -SYS ("sysctl -qw net.ipv6.conf.all.forwarding=1" ); +SYS (out,"sysctl -qw net.ipv6.conf.all.forwarding=1" ); ifindex_src =if_nametoindex ("veth_src" ); ifindex_dst =if_nametoindex ("veth_dst" );
@@ -250,6 +242,6 @@ void test_xdp_do_redirect(void) out:if (nstoken)close_netns (nstoken); -system ("ip netns del testns" ); +SYS_NOFAIL ("ip netns del testns" );test_xdp_do_redirect__destroy (skel); }
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +9 -14
@@ -34,11 +34,6 @@#define PREFIX_LEN "8"#define FAMILY AF_INET -#define SYS (cmd) ({ \ - if (!ASSERT_OK(system(cmd), (cmd))) \ - goto out; \ -}) -struct xsk {void *umem_area;struct xsk_umem *umem;
@@ -300,16 +295,16 @@ void test_xdp_metadata(void)/* Setup new networking namespace, with a veth pair. */ -SYS ("ip netns add xdp_metadata" ); +SYS (out,"ip netns add xdp_metadata" ); tok =open_netns ("xdp_metadata" ); -SYS ("ip link add numtxqueues 1 numrxqueues 1 " TX_NAME +SYS (out,"ip link add numtxqueues 1 numrxqueues 1 " TX_NAME " type veth peer " RX_NAME " numtxqueues 1 numrxqueues 1" ); -SYS ("ip link set dev " TX_NAME " address 00:00:00:00:00:01" ); -SYS ("ip link set dev " RX_NAME " address 00:00:00:00:00:02" ); -SYS ("ip link set dev " TX_NAME " up" ); -SYS ("ip link set dev " RX_NAME " up" ); -SYS ("ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME ); -SYS ("ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME ); +SYS (out,"ip link set dev " TX_NAME " address 00:00:00:00:00:01" ); +SYS (out,"ip link set dev " RX_NAME " address 00:00:00:00:00:02" ); +SYS (out,"ip link set dev " TX_NAME " up" ); +SYS (out,"ip link set dev " RX_NAME " up" ); +SYS (out,"ip addr add " TX_ADDR "/" PREFIX_LEN " dev " TX_NAME ); +SYS (out,"ip addr add " RX_ADDR "/" PREFIX_LEN " dev " RX_NAME ); rx_ifindex =if_nametoindex (RX_NAME ); tx_ifindex =if_nametoindex (TX_NAME );
@@ -407,5 +402,5 @@ void test_xdp_metadata(void)xdp_metadata__destroy (bpf_obj);if (tok)close_netns (tok); -system ("ip netns del xdp_metadata" ); +SYS_NOFAIL ("ip netns del xdp_metadata" ); }
tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c +18 -23
74 lines not on this page · raw message
tools/testing/selftests/bpf/prog_tests/xfrm_info.c +26 -41
113 lines not on this page · raw message
tools/testing/selftests/bpf/test_progs.h +15 -0
@@ -376,6 +376,21 @@ int test__join_cgroup(const char *path); ___ok; \ }) +#define SYS (goto_label, fmt, ...) \ + ({ \ + char cmd[1024]; \ + snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ + if (!ASSERT_OK(system(cmd), cmd)) \ + goto goto_label; \ + }) + +#define SYS_NOFAIL (fmt, ...) \ + ({ \ + char cmd[1024]; \ + snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \ + system(cmd); \ + }) +static inline __u64 ptr_to_u64 (const void *ptr) {return (__u64 ) (unsigned long ) ptr;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 340/694 selftests/bpf: Fix flaky fib_lookup test
In reply to Greg Kroah-HartmanFrom: Martin KaFai Lau <[email protected]>
[ Upstream commit a6865576317f6249f3f83cf4c10ab56e627ee153 ]
There is a report that fib_lookup test is flaky when running in parallel. A symptom of slowness or delay. An example:
Testing IPv6 stale neigh set_lookup_params:PASS:inet_pton(IPV6_IFACE_ADDR) 0 nsec test_fib_lookup:PASS:bpf_prog_test_run_opts 0 nsec test_fib_lookup:FAIL:fib_lookup_ret unexpected fib_lookup_ret: actual 0 != expected 7 test_fib_lookup:FAIL:dmac not match unexpected dmac not match: actual 1 != expected 0 dmac expected 11:11:11:11:11:11 actual 00:00:00:00:00:00
[ Note that the "fib_lookup_ret unexpected fib_lookup_ret actual 0 ..."
is reversed in terms of expected and actual value. Fixing in this patch also. ]
One possibility is the testing stale neigh entry was marked dead by the gc (in neigh_periodic_work). The default gc_stale_time sysctl is 60s. This patch increases it to 15 mins.
It also:
- fixes the reversed arg (actual vs expected) in one of the ASSERT_EQ test
- removes the nodad command arg when adding v4 neigh entry which currently has a warning.
--- tools/testing/selftests/bpf/prog_tests/fib_lookup.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/fib_lookup.c +10 -2
@@ -54,11 +54,19 @@ static int setup_netns(void)SYS (fail,"ip link add veth1 type veth peer name veth2" );SYS (fail,"ip link set dev veth1 up" ); + err =write_sysctl ("/proc/sys/net/ipv4/neigh/veth1/gc_stale_time" ,"900" ); +if (!ASSERT_OK (err,"write_sysctl(net.ipv4.neigh.veth1.gc_stale_time)" )) + goto fail; + + err =write_sysctl ("/proc/sys/net/ipv6/neigh/veth1/gc_stale_time" ,"900" ); +if (!ASSERT_OK (err,"write_sysctl(net.ipv6.neigh.veth1.gc_stale_time)" )) + goto fail; +SYS (fail,"ip addr add %s/64 dev veth1 nodad" ,IPV6_IFACE_ADDR );SYS (fail,"ip neigh add %s dev veth1 nud failed" ,IPV6_NUD_FAILED_ADDR );SYS (fail,"ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV6_NUD_STALE_ADDR ,DMAC ); -SYS (fail,"ip addr add %s/24 dev veth1 nodad" ,IPV4_IFACE_ADDR ); +SYS (fail,"ip addr add %s/24 dev veth1" ,IPV4_IFACE_ADDR );SYS (fail,"ip neigh add %s dev veth1 nud failed" ,IPV4_NUD_FAILED_ADDR );SYS (fail,"ip neigh add %s dev veth1 lladdr %s nud stale" ,IPV4_NUD_STALE_ADDR ,DMAC );
@@ -158,7 +166,7 @@ void test_fib_lookup(void)if (!ASSERT_OK (err,"bpf_prog_test_run_opts" ))continue ; -ASSERT_EQ (tests[i].expected_ret, skel->bss->fib_lookup_ret, +ASSERT_EQ (skel->bss->fib_lookup_ret, tests[i].expected_ret,"fib_lookup_ret" ); ret =memcmp (tests[i].dmac, fib_params->dmac,sizeof (tests[i].dmac));
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 341/694 bpf: take into account liveness when propagating precision
In reply to Greg Kroah-HartmanFrom: Andrii Nakryiko <[email protected]>
[ Upstream commit 52c2b005a3c18c565fc70cfd0ca49375f301e952 ]
When doing state comparison, if old state has register that is not marked as REG_LIVE_READ, then we just skip comparison, regardless what's the state of corresponing register in current state. This is because not REG_LIVE_READ register is irrelevant for further program execution and correctness. All good here.
But when we get to precision propagation, after two states were declared equivalent, we don't take into account old register's liveness, and thus attempt to propagate precision for register in current state even if that register in old state was not REG_LIVE_READ anymore. This is bad, because register in current state could be anything at all and this could cause -EFAULT due to internal logic bugs.
Fix by taking into account REG_LIVE_READ liveness mark to keep the logic in state comparison in sync with precision propagation.
--- kernel/bpf/verifier.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +4 -2
@@ -14225,7 +14225,8 @@ static int propagate_precision(struct bpf_verifier_env *env, state_reg = state->regs;for (i =0 ; i <BPF_REG_FP ; i++, state_reg++) {if (state_reg->type !=SCALAR_VALUE || - !state_reg->precise) + !state_reg->precise || + !(state_reg->live ®_LIVE_READ ))continue ;if (env->log.level &BPF_LOG_LEVEL2 )verbose (env,"frame %d: propagating r%d\n" , i, fr);
@@ -14239,7 +14240,8 @@ static int propagate_precision(struct bpf_verifier_env *env,continue ; state_reg = &state->stack[i].spilled_ptr;if (state_reg->type !=SCALAR_VALUE || - !state_reg->precise) + !state_reg->precise || + !(state_reg->live ®_LIVE_READ ))continue ;if (env->log.level &BPF_LOG_LEVEL2 ) verbose(env, "frame %d: propagating fp%d\n",
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 342/694 bpf: fix precision propagation verbose logging
In reply to Greg Kroah-HartmanFrom: Andrii Nakryiko <[email protected]>
[ Upstream commit 34f0677e7afd3a292bc1aadda7ce8e35faedb204 ]
Fix wrong order of frame index vs register/slot index in precision propagation verbose (level 2) output. It's wrong and very confusing as is.
--- kernel/bpf/verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +2 -2
@@ -14229,7 +14229,7 @@ static int propagate_precision(struct bpf_verifier_env *env, !(state_reg->live & REG_LIVE_READ))continue ;if (env->log.level &BPF_LOG_LEVEL2 ) -verbose (env,"frame %d: propagating r%d\n" , i, fr); +verbose (env,"frame %d: propagating r%d\n" , fr, i); err =mark_chain_precision_frame (env, fr, i);if (err <0 )return err;
@@ -14245,7 +14245,7 @@ static int propagate_precision(struct bpf_verifier_env *env,continue ;if (env->log.level &BPF_LOG_LEVEL2 )verbose (env,"frame %d: propagating fp%d\n" , - (-i -1 ) *BPF_REG_SIZE , fr); + fr, (-i -1 ) *BPF_REG_SIZE ); err =mark_chain_precision_stack_frame (env, fr, i);if (err <0 )return err;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 343/694 crypto: qat - fix concurrency issue when device state changes
In reply to Greg Kroah-HartmanFrom: Shashank Gupta <[email protected]>
[ Upstream commit 1bdc85550a2b59bb7f62ead7173134e66dd2d60e ]
The sysfs state attribute is not protected against race conditions. If multiple processes perform a device state transition on the same device in parallel, unexpected behaviors might occur.
For transitioning the device state, adf_sysfs.c calls the functions adf_dev_init(), adf_dev_start(), adf_dev_stop() and adf_dev_shutdown() which are unprotected and interdependent on each other. To perform a state transition, these functions needs to be called in a specific order:
* device up: adf_dev_init() -> adf_dev_start()
* device down: adf_dev_stop() -> adf_dev_shutdown()
This change introduces the functions adf_dev_up() and adf_dev_down() which wrap the state machine functions and protect them with a per-device lock. These are then used in adf_sysfs.c instead of the individual state transition functions.
--- .../crypto/qat/qat_common/adf_accel_devices.h | 1 + .../crypto/qat/qat_common/adf_common_drv.h | 3 + drivers/crypto/qat/qat_common/adf_dev_mgr.c | 2 + drivers/crypto/qat/qat_common/adf_init.c | 64 +++++++++++++++++++ drivers/crypto/qat/qat_common/adf_sysfs.c | 23 +------ 5 files changed, 73 insertions(+), 20 deletions(-)
drivers/crypto/qat/qat_common/adf_accel_devices.h +1 -0
@@ -310,6 +310,7 @@ struct adf_accel_dev {u8 pf_compat_ver; } vf; }; +struct mutex state_lock;/* protect state of the device */ bool is_vf;u32 accel_id; };
drivers/crypto/qat/qat_common/adf_common_drv.h +3 -0
@@ -58,6 +58,9 @@ void adf_dev_stop(struct adf_accel_dev *accel_dev);void adf_dev_shutdown (struct adf_accel_dev *accel_dev);int adf_dev_shutdown_cache_cfg (struct adf_accel_dev *accel_dev); +int adf_dev_up (struct adf_accel_dev *accel_dev,bool init_config); +int adf_dev_down (struct adf_accel_dev *accel_dev,bool cache_config); +void adf_devmgr_update_class_index (struct adf_hw_device_data *hw_data);void adf_clean_vf_map (bool );
drivers/crypto/qat/qat_common/adf_dev_mgr.c +2 -0
@@ -223,6 +223,7 @@ int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev, map->attached = true;list_add_tail (&map->list, &vfs_table); } +mutex_init (&accel_dev->state_lock); unlock:mutex_unlock (&table_lock);return ret;
@@ -269,6 +270,7 @@ void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev, } } unlock: +mutex_destroy (&accel_dev->state_lock);list_del (&accel_dev->list);mutex_unlock (&table_lock); }
drivers/crypto/qat/qat_common/adf_init.c +64 -0
67 lines not on this page · raw message
drivers/crypto/qat/qat_common/adf_sysfs.c +3 -20
@@ -50,38 +50,21 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr,switch (ret) {case DEV_DOWN : -if (!adf_dev_started (accel_dev)) { -dev_info (dev,"Device qat_dev%d already down\n" , - accel_id); -return -EINVAL ; - } -dev_info (dev,"Stopping device qat_dev%d\n" , accel_id); - ret =adf_dev_shutdown_cache_cfg (accel_dev); + ret =adf_dev_down (accel_dev, true);if (ret <0 )return -EINVAL ;break ;case DEV_UP : -if (adf_dev_started (accel_dev)) { -dev_info (dev,"Device qat_dev%d already up\n" , - accel_id); -return -EINVAL ; - } -dev_info (dev,"Starting device qat_dev%d\n" , accel_id); - ret =GET_HW_DATA (accel_dev)->dev_config (accel_dev); -if (!ret) - ret =adf_dev_init (accel_dev); -if (!ret) - ret =adf_dev_start (accel_dev); - + ret =adf_dev_up (accel_dev, true);if (ret <0 ) {dev_err (dev,"Failed to start device qat_dev%d\n" , accel_id); -adf_dev_shutdown_cache_cfg (accel_dev); +adf_dev_down (accel_dev, true);return ret; }break ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 344/694 scm: fix MSG_CTRUNC setting condition for SO_PASSSEC
In reply to Greg Kroah-HartmanFrom: Alexander Mikhalitsyn <[email protected]>
[ Upstream commit a02d83f9947d8f71904eda4de046630c3eb6802c ]
Currently, kernel would set MSG_CTRUNC flag if msg_control buffer wasn't provided and SO_PASSCRED was set or if there was pending SCM_RIGHTS.
For some reason we have no corresponding check for SO_PASSSEC.
In the recvmsg(2) doc we have:
MSG_CTRUNC
indicates that some control data was discarded due to lack of space in the buffer for ancillary data.
So, we need to set MSG_CTRUNC flag for all types of SCM.
This change can break applications those don't check MSG_CTRUNC flag.
v2:
- commit message was rewritten according to Eric's suggestion
--- include/net/scm.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
include/net/scm.h +12 -1
@@ -105,16 +105,27 @@ static inline void scm_passec(struct socket *sock, struct msghdr *msg, struct sc } } } + +static inline bool scm_has_secdata (struct socket *sock) +{ +return test_bit (SOCK_PASSSEC , &sock->flags); +}#else static inline void scm_passec (struct socket *sock,struct msghdr *msg,struct scm_cookie *scm) { } + +static inline bool scm_has_secdata (struct socket *sock) +{ +return false; +}#endif /* CONFIG_SECURITY_NETWORK */ static __inline__void scm_recv (struct socket *sock,struct msghdr *msg,struct scm_cookie *scm,int flags) {if (!msg->msg_control) { -if (test_bit (SOCK_PASSCRED , &sock->flags) || scm->fp) +if (test_bit (SOCK_PASSCRED , &sock->flags) || scm->fp || +scm_has_secdata (sock)) msg->msg_flags |=MSG_CTRUNC ;scm_destroy (scm);return ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 345/694 wifi: ath12k: Add missing unwind goto in ath12k_pci_probe()
In reply to Greg Kroah-HartmanFrom: Harshit Mogalapalli <[email protected]>
[ Upstream commit 488d9a484f96eee4f0e8e108aed42a057a1c7295 ]
Smatch Warns:
drivers/net/wireless/ath/ath12k/pci.c:1198 ath12k_pci_probe() warn: missing unwind goto?
Store the error value in ret and use correct label with a goto.
Only Compile tested, found with Smatch.
--- drivers/net/wireless/ath/ath12k/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/pci.c +2 -1
@@ -1195,7 +1195,8 @@ static int ath12k_pci_probe(struct pci_dev *pdev,dev_err (&pdev->dev,"Unknown hardware version found for QCN9274: 0x%x\n" , soc_hw_version_major); -return -EOPNOTSUPP ; + ret = -EOPNOTSUPP ; + goto err_pci_free_region; }break ;case WCN7850_DEVICE_ID :
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 346/694 wifi: ath11k: fix deinitialization of firmware resources
In reply to Greg Kroah-HartmanFrom: Aditya Kumar Singh <[email protected]>
[ Upstream commit 5a78ac33e3cb8822da64dd1af196e83664b332b0 ]
Currently, in ath11k_ahb_fw_resources_init(), iommu domain mapping is done only for the chipsets having fixed firmware memory. Also, for such chipsets, mapping is done only if it does not have TrustZone support.
During deinitialization, only if TrustZone support is not there, iommu is unmapped back. However, for non fixed firmware memory chipsets, TrustZone support is not there and this makes the condition check to true and it tries to unmap the memory which was not mapped during initialization.
This leads to the following trace -
[ 83.198790] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008 [ 83.259537] Modules linked in: ath11k_ahb ath11k qmi_helpers .. snip .. [ 83.280286] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 83.287228] pc : __iommu_unmap+0x30/0x140 [ 83.293907] lr : iommu_unmap+0x5c/0xa4 [ 83.298072] sp : ffff80000b3abad0 .. snip .. [ 83.369175] Call trace: [ 83.376282] __iommu_unmap+0x30/0x140 [ 83.378541] iommu_unmap+0x5c/0xa4 [ 83.382360] ath11k_ahb_fw_resource_deinit.part.12+0x2c/0xac [ath11k_ahb] [ 83.385666] ath11k_ahb_free_resources+0x140/0x17c [ath11k_ahb] [ 83.392521] ath11k_ahb_shutdown+0x34/0x40 [ath11k_ahb] [ 83.398248] platform_shutdown+0x20/0x2c [ 83.403455] device_shutdown+0x16c/0x1c4 [ 83.407621] kernel_restart_prepare+0x34/0x3c [ 83.411529] kernel_restart+0x14/0x74 [ 83.415781] __do_sys_reboot+0x1c4/0x22c [ 83.419427] __arm64_sys_reboot+0x1c/0x24 [ 83.423420] invoke_syscall+0x44/0xfc [ 83.427326] el0_svc_common.constprop.3+0xac/0xe8 [ 83.430974] do_el0_svc+0xa0/0xa8 [ 83.435659] el0_svc+0x1c/0x44 [ 83.438957] el0t_64_sync_handler+0x60/0x144 [ 83.441910] el0t_64_sync+0x15c/0x160 [ 83.446343] Code: aa0103f4 f9400001 f90027a1 d2800001 (f94006a0) [ 83.449903] ---[ end trace 0000000000000000 ]---
This can be reproduced by probing an AHB chipset which is not having a fixed memory region. During reboot (or rmmod) trace can be seen.
Fix this issue by adding a condition check on firmware fixed memory hw_param as done in the counter initialization function.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.7.0.1-01744-QCAHKSWPL_SILICONZ-1
--- drivers/net/wireless/ath/ath11k/ahb.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/ath/ath11k/ahb.c +6 -0
@@ -1078,6 +1078,12 @@ static int ath11k_ahb_fw_resource_deinit(struct ath11k_base *ab)struct iommu_domain *iommu;size_t unmapped_size; +/* Chipsets not requiring MSA would have not initialized +* MSA resources, return success in such cases. +*/ +if (!ab->hw_params.fixed_fw_mem) +return 0 ; +if (ab_ahb->fw.use_tz)return 0 ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 347/694 selftests/bpf: Fix a fd leak in an error path in network_helpers.c
In reply to Greg Kroah-HartmanFrom: Martin KaFai Lau <[email protected]>
[ Upstream commit 226efec2b0efad60d4a6c4b2c3a8710dafc4dc21 ]
In __start_server, it leaks a fd when setsockopt(SO_REUSEPORT) fails. This patch fixes it.
--- tools/testing/selftests/bpf/network_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/network_helpers.c +1 -1
@@ -95,7 +95,7 @@ static int __start_server(int type, int protocol, const struct sockaddr *addr,if (reuseport &&setsockopt (fd,SOL_SOCKET ,SO_REUSEPORT , &on,sizeof (on))) {log_err ("Failed to set SO_REUSEPORT" ); -return -1 ; + goto error_close; }if (bind (fd, addr, addrlen) <0 ) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 348/694 bpf: Only allocate one bpf_mem_cache for bpf_cpumask_ma
In reply to Greg Kroah-HartmanFrom: Hou Tao <[email protected]>
[ Upstream commit 5d5de3a431d87ac51d43da8d796891d014975ab7 ]
The size of bpf_cpumask is fixed, so there is no need to allocate many bpf_mem_caches for bpf_cpumask_ma, just one bpf_mem_cache is enough. Also add comments for bpf_mem_alloc_init() in bpf_mem_alloc.h to prevent future miuse.
Stable-dep-of: 77473d1a962f ("bpf: Free struct bpf_cpumask in call_rcu handler")
--- include/linux/bpf_mem_alloc.h | 7 +++++++ kernel/bpf/cpumask.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-)
include/linux/bpf_mem_alloc.h +7 -0
@@ -14,6 +14,13 @@ struct bpf_mem_alloc {struct work_struct work; }; +/* 'size != 0' is for bpf_mem_alloc which manages fixed-size objects. +* Alloc and free are done with bpf_mem_cache_{alloc,free}(). +* +* 'size = 0' is for bpf_mem_alloc which manages many fixed-size objects. +* Alloc and free are done with bpf_mem_{alloc,free}() and the size of +* the returned object is given by the size argument of bpf_mem_alloc(). +*/ int bpf_mem_alloc_init (struct bpf_mem_alloc *ma,int size,bool percpu);void bpf_mem_alloc_destroy (struct bpf_mem_alloc *ma);
kernel/bpf/cpumask.c +3 -3
@@ -55,7 +55,7 @@ __bpf_kfunc struct bpf_cpumask *bpf_cpumask_create(void)/* cpumask must be the first element so struct bpf_cpumask be cast to struct cpumask. */ BUILD_BUG_ON (offsetof(struct bpf_cpumask , cpumask) !=0 ); - cpumask =bpf_mem_alloc (&bpf_cpumask_ma,sizeof (*cpumask)); + cpumask =bpf_mem_cache_alloc (&bpf_cpumask_ma);if (!cpumask)return NULL ;
@@ -123,7 +123,7 @@ __bpf_kfunc void bpf_cpumask_release(struct bpf_cpumask *cpumask)if (refcount_dec_and_test (&cpumask->usage)) {migrate_disable (); -bpf_mem_free (&bpf_cpumask_ma, cpumask); +bpf_mem_cache_free (&bpf_cpumask_ma, cpumask);migrate_enable (); } }
@@ -468,7 +468,7 @@ static int __init cpumask_kfunc_init(void) }, }; - ret =bpf_mem_alloc_init (&bpf_cpumask_ma,0 , false); + ret =bpf_mem_alloc_init (&bpf_cpumask_ma,sizeof (struct bpf_cpumask ), false); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_TRACING , &cpumask_kfunc_set); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , &cpumask_kfunc_set); return ret ?: register_btf_id_dtor_kfuncs(cpumask_dtors,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 349/694 bpf: Free struct bpf_cpumask in call_rcu handler
In reply to Greg Kroah-HartmanFrom: David Vernet <[email protected]>
[ Upstream commit 77473d1a962f3d4f7ba48324502b6d27b8ef2591 ]
The struct bpf_cpumask type uses the bpf_mem_cache_{alloc,free}() APIs to allocate and free its cpumasks. The bpf_mem allocator may currently immediately reuse some memory when its freed, without waiting for an RCU read cycle to elapse. We want to be able to treat struct bpf_cpumask objects as completely RCU safe.
This is necessary for two reasons:
1. bpf_cpumask_kptr_get() currently does an RCU-protected refcnt_inc_not_zero(). This of course assumes that the underlying memory is not reused, and is therefore unsafe in its current form.
2. We want to be able to get rid of bpf_cpumask_kptr_get() entirely, and intead use the superior kptr RCU semantics now afforded by the verifier.
This patch fixes (1), and enables (2), by making struct bpf_cpumask RCU safe. A subsequent patch will update the verifier to allow struct bpf_cpumask * pointers to be passed to KF_RCU kfuncs, and then a latter patch will remove bpf_cpumask_kptr_get().
--- kernel/bpf/cpumask.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
kernel/bpf/cpumask.c +14 -5
@@ -9,6 +9,7 @@/** * struct bpf_cpumask - refcounted BPF cpumask wrapper structure * @cpumask: The actual cpumask embedded in the struct. +* @rcu: The RCU head used to free the cpumask with RCU safety. * @usage: Object reference counter. When the refcount goes to 0, the * memory is released back to the BPF allocator, which provides * RCU safety.
@@ -24,6 +25,7 @@*/ struct bpf_cpumask {cpumask_t cpumask; +struct rcu_head rcu;refcount_t usage; };
@@ -108,6 +110,16 @@ __bpf_kfunc struct bpf_cpumask *bpf_cpumask_kptr_get(struct bpf_cpumask **cpumasreturn cpumask; } +static void cpumask_free_cb (struct rcu_head *head) +{ +struct bpf_cpumask *cpumask; + + cpumask = container_of(head, struct bpf_cpumask, rcu); +migrate_disable (); +bpf_mem_cache_free (&bpf_cpumask_ma, cpumask); +migrate_enable (); +} +/** * bpf_cpumask_release() - Release a previously acquired BPF cpumask. * @cpumask: The cpumask being released.
@@ -121,11 +133,8 @@ __bpf_kfunc void bpf_cpumask_release(struct bpf_cpumask *cpumask)if (!cpumask)return ; -if (refcount_dec_and_test (&cpumask->usage)) { -migrate_disable (); -bpf_mem_cache_free (&bpf_cpumask_ma, cpumask); -migrate_enable (); - } +if (refcount_dec_and_test (&cpumask->usage)) +call_rcu (&cpumask->rcu, cpumask_free_cb); }/**
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 350/694 bpf: Remove misleading spec_v1 check on var-offset stack read
In reply to Greg Kroah-HartmanFrom: Luis Gerhorst <[email protected]>
[ Upstream commit 082cdc69a4651dd2a77539d69416a359ed1214f5 ]
For every BPF_ADD/SUB involving a pointer, adjust_ptr_min_max_vals() ensures that the resulting pointer has a constant offset if bypass_spec_v1 is false. This is ensured by calling sanitize_check_bounds() which in turn calls check_stack_access_for_ptr_arithmetic(). There, -EACCESS is returned if the register's offset is not constant, thereby rejecting the program.
In summary, an unprivileged user must never be able to create stack pointers with a variable offset. That is also the case, because a respective check in check_stack_write() is missing. If they were able to create a variable-offset pointer, users could still use it in a stack-write operation to trigger unsafe speculative behavior [1].
Because unprivileged users must already be prevented from creating variable-offset stack pointers, viable options are to either remove this check (replacing it with a clarifying comment), or to turn it into a "verifier BUG"-message, also adding a similar check in check_stack_write() (for consistency, as a second-level defense). This patch implements the first option to reduce verifier bloat.
This check was introduced by commit 01f810ace9ed ("bpf: Allow variable-offset stack access") which correctly notes that "variable-offset reads and writes are disallowed (they were already disallowed for the indirect access case) because the speculative execution checking code doesn't support them". However, it does not further discuss why the check in check_stack_read() is necessary. The code which made this check obsolete was also introduced in this commit.
I have compiled ~650 programs from the Linux selftests, Linux samples, Cilium, and libbpf/examples projects and confirmed that none of these trigger the check in check_stack_read() [2]. Instead, all of these programs are, as expected, already rejected when constructing the variable-offset pointers. Note that the check in check_stack_access_for_ptr_arithmetic() also prints "off=%d" while the code removed by this patch does not (the error removed does not appear in the "verification_error" values). For reproducibility, the repository linked includes the raw data and scripts used to create the plot.
[1] https://arxiv.org/pdf/1807.03757.pdf
[2] https://gitlab.cs.fau.de/un65esoq/bpf-spectre/-/raw/53dc19fcf459c186613b1156a81504b39c8d49db/data/plots/23-02-26_23-56_bpftool/bpftool/0004-errors.pdf?inline=false
--- kernel/bpf/verifier.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
kernel/bpf/verifier.c +6 -10
@@ -3977,17 +3977,13 @@ static int check_stack_read(struct bpf_verifier_env *env, }/* Variable offset is prohibited for unprivileged mode for simplicity * since it requires corresponding support in Spectre masking for stack -* ALU. See also retrieve_ptr_limit(). +* ALU. See also retrieve_ptr_limit(). The check in +* check_stack_access_for_ptr_arithmetic() called by +* adjust_ptr_min_max_vals() prevents users from creating stack pointers +* with variable offsets, therefore no check is required here. Further, +* just checking it here would be insufficient as speculative stack +* writes could still lead to unsafe speculative behaviour. */ -if (!env->bypass_spec_v1 && var_off) { -char tn_buf[48 ]; - -tnum_strn (tn_buf,sizeof (tn_buf), reg->var_off); -verbose (env,"R%d variable offset stack access prohibited for !root, var_off=%s\n" , - ptr_regno, tn_buf); -return -EACCES ; - } -if (!var_off) { off += reg->var_off.value; err = check_stack_read_fixed_off(env, state, off, size,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 351/694 net: pcs: xpcs: remove double-read of link state when using AN
In reply to Greg Kroah-HartmanFrom: Russell King (Oracle) <[email protected]>
[ Upstream commit ef63461caf427a77a04620d74ba90035a712af9c ]
Phylink does not want the current state of the link when reading the PCS link state - it wants the latched state. Don't double-read the MII status register. Phylink will re-read as necessary to capture transient link-down events as of dbae3388ea9c ("net: phylink: Force retrigger in case of latched link-fail indicator").
The above referenced commit is a dependency for this change, and thus this change should not be backported to any kernel that does not contain the above referenced commit.
--- drivers/net/pcs/pcs-xpcs.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/net/pcs/pcs-xpcs.c +2 -11
@@ -321,7 +321,7 @@ static int xpcs_read_fault_c73(struct dw_xpcs *xpcs,return 0 ; } -static int xpcs_read_link_c73 (struct dw_xpcs *xpcs,bool an) +static int xpcs_read_link_c73 (struct dw_xpcs *xpcs) {bool link = true;int ret;
@@ -333,15 +333,6 @@ static int xpcs_read_link_c73(struct dw_xpcs *xpcs, bool an)if (!(ret &MDIO_STAT1_LSTATUS )) link = false; -if (an) { - ret =xpcs_read (xpcs,MDIO_MMD_AN ,MDIO_STAT1 ); -if (ret <0 ) -return ret; - -if (!(ret &MDIO_STAT1_LSTATUS )) - link = false; - } -return link; }
@@ -935,7 +926,7 @@ static int xpcs_get_state_c73(struct dw_xpcs *xpcs,int ret;/* Link needs to be read first ... */ - state->link =xpcs_read_link_c73 (xpcs, state->an_enabled) >0 ?1 :0 ; + state->link =xpcs_read_link_c73 (xpcs) >0 ?1 :0 ;/* ... and then we check the faults. */ ret =xpcs_read_fault_c73 (xpcs, state);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 352/694 vlan: partially enable SIOCSHWTSTAMP in container
In reply to Greg Kroah-HartmanFrom: Vadim Fedorenko <[email protected]>
[ Upstream commit 731b73dba359e3ff00517c13aa0daa82b34ff466 ]
Setting timestamp filter was explicitly disabled on vlan devices in containers because it might affect other processes on the host. But it's absolutely legit in case when real device is in the same namespace.
--- net/8021q/vlan_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/8021q/vlan_dev.c +1 -1
@@ -365,7 +365,7 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)switch (cmd) {case SIOCSHWTSTAMP : -if (!net_eq (dev_net (dev), &init_net)) +if (!net_eq (dev_net (dev),dev_net (real_dev)))break ; fallthrough;case SIOCGMIIPHY :
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 353/694 net/packet: annotate accesses to po->xmit
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
[ Upstream commit b9d83ab8a708f23a4001d60e9d8d0b3be3d9f607 ]
po->xmit can be set from setsockopt(PACKET_QDISC_BYPASS), while read locklessly.
Use READ_ONCE()/WRITE_ONCE() to avoid potential load/store tearing issues.
--- net/packet/af_packet.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/packet/af_packet.c +8 -4
@@ -307,7 +307,8 @@ static void packet_cached_dev_reset(struct packet_sock *po)static bool packet_use_direct_xmit (const struct packet_sock *po) { -return po->xmit == packet_direct_xmit; +/* Paired with WRITE_ONCE() in packet_setsockopt() */ +return READ_ONCE (po->xmit) == packet_direct_xmit; }static u16 packet_pick_tx_queue (struct sk_buff *skb)
@@ -2867,7 +2868,8 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)packet_inc_pending (&po->tx_ring); status =TP_STATUS_SEND_REQUEST ; - err = po->xmit (skb); +/* Paired with WRITE_ONCE() in packet_setsockopt() */ + err =READ_ONCE (po->xmit)(skb);if (unlikely (err !=0 )) {if (err >0 ) err =net_xmit_errno (err);
@@ -3070,7 +3072,8 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)virtio_net_hdr_set_proto (skb, &vnet_hdr); } - err = po->xmit (skb); +/* Paired with WRITE_ONCE() in packet_setsockopt() */ + err =READ_ONCE (po->xmit)(skb);if (unlikely (err !=0 )) {if (err >0 ) err =net_xmit_errno (err);
@@ -4007,7 +4010,8 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,if (copy_from_sockptr (&val, optval,sizeof (val)))return -EFAULT ; - po->xmit = val ? packet_direct_xmit : dev_queue_xmit; +/* Paired with all lockless reads of po->xmit */ +WRITE_ONCE (po->xmit, val ? packet_direct_xmit : dev_queue_xmit);return 0 ; }default :
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 354/694 net/packet: convert po->origdev to an atomic flag
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
[ Upstream commit ee5675ecdf7a4e713ed21d98a70c2871d6ebed01 ]
syzbot/KCAN reported that po->origdev can be read
while another thread is changing its value.
We can avoid this splat by converting this field
to an actual bit.
Following patches will convert remaining 1bit fields.
--- net/packet/af_packet.c | 10 ++++------ net/packet/diag.c | 2 +- net/packet/internal.h | 22 +++++++++++++++++++++- 3 files changed, 26 insertions(+), 8 deletions(-)
net/packet/af_packet.c +4 -6
@@ -2184,7 +2184,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, sll = &PACKET_SKB_CB (skb)->sa.ll; sll->sll_hatype = dev->type; sll->sll_pkttype = skb->pkt_type; -if (unlikely (po->origdev)) +if (unlikely (packet_sock_flag (po,PACKET_SOCK_ORIGDEV ))) sll->sll_ifindex = orig_dev->ifindex;else sll->sll_ifindex = dev->ifindex;
@@ -2461,7 +2461,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, sll->sll_hatype = dev->type; sll->sll_protocol = skb->protocol; sll->sll_pkttype = skb->pkt_type; -if (unlikely (po->origdev)) +if (unlikely (packet_sock_flag (po,PACKET_SOCK_ORIGDEV ))) sll->sll_ifindex = orig_dev->ifindex;else sll->sll_ifindex = dev->ifindex;
@@ -3914,9 +3914,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,if (copy_from_sockptr (&val, optval,sizeof (val)))return -EFAULT ; -lock_sock (sk); - po->origdev = !!val; -release_sock (sk); +packet_sock_flag_set (po,PACKET_SOCK_ORIGDEV , val);return 0 ; }case PACKET_VNET_HDR :
@@ -4065,7 +4063,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname, val = po->auxdata;break ;case PACKET_ORIGDEV : - val = po->origdev; + val =packet_sock_flag (po,PACKET_SOCK_ORIGDEV );break ;case PACKET_VNET_HDR : val = po->has_vnet_hdr;
net/packet/diag.c +1 -1
@@ -25,7 +25,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb) pinfo.pdi_flags |=PDI_RUNNING ;if (po->auxdata) pinfo.pdi_flags |=PDI_AUXDATA ; -if (po->origdev) +if (packet_sock_flag (po,PACKET_SOCK_ORIGDEV )) pinfo.pdi_flags |=PDI_ORIGDEV ;if (po->has_vnet_hdr) pinfo.pdi_flags |=PDI_VNETHDR ;
net/packet/internal.h +21 -1
@@ -116,9 +116,9 @@ struct packet_sock {int copy_thresh;spinlock_t bind_lock;struct mutex pg_vec_lock; +unsigned long flags;unsigned int running;/* bind_lock must be held */ unsigned int auxdata:1, /* writer must hold sock lock */ - origdev:1, has_vnet_hdr:1, tp_loss:1, tp_tx_has_off:1;
@@ -144,4 +144,24 @@ static inline struct packet_sock *pkt_sk(struct sock *sk) return (struct packet_sock *)sk; } +enum packet_sock_flags { +PACKET_SOCK_ORIGDEV , +}; + +static inline void packet_sock_flag_set (struct packet_sock *po, +enum packet_sock_flags flag, +bool val) +{ +if (val) +set_bit (flag, &po->flags); +else +clear_bit (flag, &po->flags); +} + +static inline bool packet_sock_flag (const struct packet_sock *po, +enum packet_sock_flags flag) +{ +return test_bit (flag, &po->flags); +} +#endif
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 355/694 net/packet: convert po->auxdata to an atomic flag
In reply to Greg Kroah-HartmanFrom: Eric Dumazet <[email protected]>
[ Upstream commit fd53c297aa7b077ae98a3d3d2d3aa278a1686ba6 ]
po->auxdata can be read while another thread is changing its value, potentially raising KCSAN splat.
Convert it to PACKET_SOCK_AUXDATA flag.
--- net/packet/af_packet.c | 8 +++----- net/packet/diag.c | 2 +- net/packet/internal.h | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-)
net/packet/af_packet.c +3 -5
@@ -3514,7 +3514,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,memcpy (msg->msg_name, &PACKET_SKB_CB (skb)->sa, copy_len); } -if (pkt_sk (sk)->auxdata) { +if (packet_sock_flag (pkt_sk (sk),PACKET_SOCK_AUXDATA )) {struct tpacket_auxdata aux; aux.tp_status =TP_STATUS_USER ;
@@ -3900,9 +3900,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, sockptr_t optval,if (copy_from_sockptr (&val, optval,sizeof (val)))return -EFAULT ; -lock_sock (sk); - po->auxdata = !!val; -release_sock (sk); +packet_sock_flag_set (po,PACKET_SOCK_AUXDATA , val);return 0 ; }case PACKET_ORIGDEV :
@@ -4060,7 +4058,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,break ;case PACKET_AUXDATA : - val = po->auxdata; + val =packet_sock_flag (po,PACKET_SOCK_AUXDATA );break ;case PACKET_ORIGDEV : val =packet_sock_flag (po,PACKET_SOCK_ORIGDEV );
net/packet/diag.c +1 -1
@@ -23,7 +23,7 @@ static int pdiag_put_info(const struct packet_sock *po, struct sk_buff *nlskb) pinfo.pdi_flags =0 ;if (po->running) pinfo.pdi_flags |=PDI_RUNNING ; -if (po->auxdata) +if (packet_sock_flag (po,PACKET_SOCK_AUXDATA )) pinfo.pdi_flags |=PDI_AUXDATA ;if (packet_sock_flag (po,PACKET_SOCK_ORIGDEV )) pinfo.pdi_flags |=PDI_ORIGDEV ;
net/packet/internal.h +2 -2
@@ -118,8 +118,7 @@ struct packet_sock {struct mutex pg_vec_lock;unsigned long flags;unsigned int running;/* bind_lock must be held */ - unsigned int auxdata:1, /* writer must hold sock lock */ - has_vnet_hdr:1, + unsigned int has_vnet_hdr:1, /* writer must hold sock lock */ tp_loss:1, tp_tx_has_off:1;int pressure;
@@ -146,6 +145,7 @@ static inline struct packet_sock *pkt_sk(struct sock *sk)enum packet_sock_flags {PACKET_SOCK_ORIGDEV , +PACKET_SOCK_AUXDATA , }; static inline void packet_sock_flag_set(struct packet_sock *po,
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 356/694 libbpf: Fix ld_imm64 copy logic for ksym in light skeleton.
In reply to Greg Kroah-HartmanFrom: Alexei Starovoitov <[email protected]>
[ Upstream commit a506d6ce1dd184051037dc9d26c3eb187c9fe625 ]
Unlike normal libbpf the light skeleton 'loader' program is doing btf_find_by_name_kind() call at run-time to find ksym in the kernel and populate its {btf_id, btf_obj_fd} pair in ld_imm64 insn. To avoid doing the search multiple times for the same ksym it remembers the first patched ld_imm64 insn and copies {btf_id, btf_obj_fd} from it into subsequent ld_imm64 insn. Fix a bug in copying logic, since it may incorrectly clear BPF_PSEUDO_BTF_ID flag.
Also replace always true if (btf_obj_fd >= 0) check with unconditional JMP_JA to clarify the code.
--- tools/lib/bpf/gen_loader.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
tools/lib/bpf/gen_loader.c +6 -4
@@ -804,11 +804,13 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo,return ;/* try to copy from existing ldimm64 insn */ if (kdesc->ref >1 ) { -move_blob2blob (gen, insn + offsetof(struct bpf_insn , imm),4 , - kdesc->insn + offsetof(struct bpf_insn , imm));move_blob2blob (gen, insn +sizeof (struct bpf_insn ) + offsetof(struct bpf_insn , imm),4 , kdesc->insn +sizeof (struct bpf_insn ) + offsetof(struct bpf_insn , imm)); -/* jump over src_reg adjustment if imm is not 0, reuse BPF_REG_0 from move_blob2blob */ +move_blob2blob (gen, insn + offsetof(struct bpf_insn , imm),4 , + kdesc->insn + offsetof(struct bpf_insn , imm)); +/* jump over src_reg adjustment if imm (btf_id) is not 0, reuse BPF_REG_0 from move_blob2blob +* If btf_id is zero, clear BPF_PSEUDO_BTF_ID flag in src_reg of ld_imm64 insn +*/ emit (gen,BPF_JMP_IMM (BPF_JNE ,BPF_REG_0 ,0 ,3 )); goto clear_src_reg; }
@@ -831,7 +833,7 @@ static void emit_relo_ksym_btf(struct bpf_gen *gen, struct ksym_relo_desc *relo,emit (gen,BPF_STX_MEM (BPF_W ,BPF_REG_8 ,BPF_REG_7 ,sizeof (struct bpf_insn ) + offsetof(struct bpf_insn , imm)));/* skip src_reg adjustment */ -emit (gen,BPF_JMP_IMM (BPF_JSGE ,BPF_REG_7 ,0 ,3 )); +emit (gen,BPF_JMP_IMM (BPF_JA ,0 ,0 ,3 )); clear_src_reg:/* clear bpf_object__relocate_data's src_reg assignment, otherwise we get a verifier failure */ reg_mask =src_reg_mask ();
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 357/694 net: dsa: qca8k: remove assignment of an_enabled in pcs_get_state()
In reply to Greg Kroah-HartmanFrom: Russell King (Oracle) <[email protected]>
[ Upstream commit 9ef70d0130f282638b28cfce24222f71ada00c9c ]
pcs_get_state() implementations are not supposed to alter an_enabled. Remove this assignment.
--- drivers/net/dsa/qca/qca8k-8xxx.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/dsa/qca/qca8k-8xxx.c +0 -1
@@ -1483,7 +1483,6 @@ static void qca8k_pcs_get_state(struct phylink_pcs *pcs, state->link = !!(reg &QCA8K_PORT_STATUS_LINK_UP ); state->an_complete = state->link; - state->an_enabled = !!(reg &QCA8K_PORT_STATUS_LINK_AUTO ); state->duplex = (reg &QCA8K_PORT_STATUS_DUPLEX ) ?DUPLEX_FULL :DUPLEX_HALF ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 358/694 netfilter: keep conntrack reference until IPsecv6 policy checks are done
In reply to Greg Kroah-HartmanFrom: Madhu Koriginja <[email protected]>
[ Upstream commit b0e214d212030fe497d4d150bb3474e50ad5d093 ]
Keep the conntrack reference until policy checks have been performed for IPsec V6 NAT support, just like ipv4.
The reference needs to be dropped before a packet is queued to avoid having the conntrack module unloadable.
--- net/dccp/ipv6.c | 1 + net/ipv6/ip6_input.c | 14 ++++++-------- net/ipv6/raw.c | 5 ++--- net/ipv6/tcp_ipv6.c | 2 ++ net/ipv6/udp.c | 2 ++ 5 files changed, 13 insertions(+), 11 deletions(-)
net/dccp/ipv6.c +1 -0
@@ -783,6 +783,7 @@ static int dccp_v6_rcv(struct sk_buff *skb)if (!xfrm6_policy_check (sk,XFRM_POLICY_IN , skb)) goto discard_and_relse; +nf_reset_ct (skb);return __sk_receive_skb (sk, skb,1 , dh->dccph_doff *4 , refcounted) ?-1 :0 ;
net/ipv6/ip6_input.c +6 -8
@@ -404,10 +404,6 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr,/* Only do this once for first final protocol */ have_final = true; -/* Free reference early: we don't need it any more, -and it may hold ip_conntrack module loaded -indefinitely. */ -nf_reset_ct (skb);skb_postpull_rcsum (skb,skb_network_header (skb),skb_network_header_len (skb));
@@ -430,10 +426,12 @@ void ip6_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int nexthdr, goto discard; } } -if (!(ipprot->flags &INET6_PROTO_NOPOLICY ) && - !xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) { -SKB_DR_SET (reason,XFRM_POLICY ); - goto discard; +if (!(ipprot->flags &INET6_PROTO_NOPOLICY )) { +if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) { +SKB_DR_SET (reason,XFRM_POLICY ); + goto discard; + } +nf_reset_ct (skb); } ret = INDIRECT_CALL_2(ipprot->handler, tcp_v6_rcv, udpv6_rcv,
net/ipv6/raw.c +2 -3
@@ -193,10 +193,8 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr)struct sk_buff *clone =skb_clone (skb,GFP_ATOMIC );/* Not releasing hash table! */ -if (clone) { -nf_reset_ct (clone); +if (clone)rawv6_rcv (sk, clone); - } } }rcu_read_unlock ();
@@ -389,6 +387,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)kfree_skb_reason (skb,SKB_DROP_REASON_XFRM_POLICY );return NET_RX_DROP ; } +nf_reset_ct (skb);if (!rp->checksum) skb->ip_summed =CHECKSUM_UNNECESSARY ;
net/ipv6/tcp_ipv6.c +2 -0
@@ -1722,6 +1722,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (drop_reason) goto discard_and_relse; +nf_reset_ct (skb); +if (tcp_filter (sk, skb)) { drop_reason =SKB_DROP_REASON_SOCKET_FILTER ; goto discard_and_relse;
net/ipv6/udp.c +2 -0
@@ -704,6 +704,7 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) drop_reason =SKB_DROP_REASON_XFRM_POLICY ; goto drop; } +nf_reset_ct (skb);if (static_branch_unlikely (&udpv6_encap_needed_key) && up->encap_type) {int (*encap_rcv)(struct sock *sk,struct sk_buff *skb);
@@ -1027,6 +1028,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) goto discard; +nf_reset_ct (skb);if (udp_lib_checksum_complete (skb)) goto csum_error;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 359/694 bpf: return long from bpf_map_ops funcs
In reply to Greg Kroah-HartmanFrom: JP Kobryn <[email protected]>
[ Upstream commit d7ba4cc900bf1eea2d8c807c6b1fc6bd61f41237 ]
This patch changes the return types of bpf_map_ops functions to long, where previously int was returned. Using long allows for bpf programs to maintain the sign bit in the absence of sign extension during situations where inlined bpf helper funcs make calls to the bpf_map_ops funcs and a negative error is returned.
The definitions of the helper funcs are generated from comments in the bpf uapi header at include/uapi/linux/bpf.h. The return type of these helpers was previously changed from int to long in commit bdb7b79b4ce8. For any case where one of the map helpers call the bpf_map_ops funcs that are still returning 32-bit int, a compiler might not include sign extension instructions to properly convert the 32-bit negative value a 64-bit negative value.
For example:
bpf assembly excerpt of an inlined helper calling a kernel function and checking for a specific error:
; err = bpf_map_update_elem(&mymap, &key, &val, BPF_NOEXIST);
...
46: call 0xffffffffe103291c ; htab_map_update_elem
; if (err && err != -EEXIST) {
4b: cmp $0xffffffffffffffef,%rax ; cmp -EEXIST,%rax
kernel function assembly excerpt of return value from htab_map_update_elem returning 32-bit int:
movl $0xffffffef, %r9d
...
movl %r9d, %eax
...results in the comparison:
cmp $0xffffffffffffffef, $0x00000000ffffffef
--- include/linux/bpf.h | 14 ++++++------- include/linux/filter.h | 6 +++--- kernel/bpf/arraymap.c | 12 ++++++------ kernel/bpf/bloom_filter.c | 12 ++++++------ kernel/bpf/bpf_cgrp_storage.c | 6 +++--- kernel/bpf/bpf_inode_storage.c | 6 +++--- kernel/bpf/bpf_struct_ops.c | 6 +++--- kernel/bpf/bpf_task_storage.c | 6 +++--- kernel/bpf/cpumap.c | 8 ++++---- kernel/bpf/devmap.c | 24 +++++++++++------------ kernel/bpf/hashtab.c | 36 +++++++++++++++++----------------- kernel/bpf/local_storage.c | 6 +++--- kernel/bpf/lpm_trie.c | 6 +++--- kernel/bpf/queue_stack_maps.c | 22 ++++++++++----------- kernel/bpf/reuseport_array.c | 2 +- kernel/bpf/ringbuf.c | 6 +++--- kernel/bpf/stackmap.c | 6 +++--- kernel/bpf/verifier.c | 14 ++++++------- net/core/bpf_sk_storage.c | 6 +++--- net/core/sock_map.c | 8 ++++---- net/xdp/xskmap.c | 8 ++++---- 21 files changed, 110 insertions(+), 110 deletions(-)
include/linux/bpf.h +7 -7
@@ -96,11 +96,11 @@ struct bpf_map_ops {/* funcs callable from userspace and from eBPF programs */ void *(*map_lookup_elem)(struct bpf_map *map,void *key); -int (*map_update_elem)(struct bpf_map *map,void *key,void *value,u64 flags); -int (*map_delete_elem)(struct bpf_map *map,void *key); -int (*map_push_elem)(struct bpf_map *map,void *value,u64 flags); -int (*map_pop_elem)(struct bpf_map *map,void *value); -int (*map_peek_elem)(struct bpf_map *map,void *value); +long (*map_update_elem)(struct bpf_map *map,void *key,void *value,u64 flags); +long (*map_delete_elem)(struct bpf_map *map,void *key); +long (*map_push_elem)(struct bpf_map *map,void *value,u64 flags); +long (*map_pop_elem)(struct bpf_map *map,void *value); +long (*map_peek_elem)(struct bpf_map *map,void *value);void *(*map_lookup_percpu_elem)(struct bpf_map *map,void *key,u32 cpu);/* funcs called by prog_array and perf_event_array map */
@@ -139,7 +139,7 @@ struct bpf_map_ops {struct bpf_local_storage __rcu ** (*map_owner_storage_ptr)(void *owner);/* Misc helpers.*/ -int (*map_redirect)(struct bpf_map *map,u64 key,u64 flags); +long (*map_redirect)(struct bpf_map *map,u64 key,u64 flags);/* map_meta_equal must be implemented for maps that can be * used as an inner map. It is a runtime check to ensure
@@ -157,7 +157,7 @@ struct bpf_map_ops {int (*map_set_for_each_callback_args)(struct bpf_verifier_env *env,struct bpf_func_state *caller,struct bpf_func_state *callee); -int (*map_for_each_callback)(struct bpf_map *map, +long (*map_for_each_callback)(struct bpf_map *map,bpf_callback_t callback_fn,void *callback_ctx,u64 flags);
include/linux/filter.h +3 -3
@@ -1504,9 +1504,9 @@ static inline bool bpf_sk_lookup_run_v6(struct net *net, int protocol, }#endif /* IS_ENABLED(CONFIG_IPV6) */ -static __always_inline int __bpf_xdp_redirect_map(struct bpf_map *map, u64 index, -u64 flags,const u64 flag_mask, -void *lookup_elem (struct bpf_map *map,u32 key)) +static __always_inline long __bpf_xdp_redirect_map (struct bpf_map *map,u64 index, +u64 flags,const u64 flag_mask, +void *lookup_elem (struct bpf_map *map,u32 key)) {struct bpf_redirect_info *ri =this_cpu_ptr (&bpf_redirect_info);const u64 action_mask =XDP_ABORTED |XDP_DROP |XDP_PASS |XDP_TX ;
kernel/bpf/arraymap.c +6 -6
@@ -307,8 +307,8 @@ static int array_map_get_next_key(struct bpf_map *map, void *key, void *next_key }/* Called from syscall or from eBPF program */ -static int array_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long array_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) { struct bpf_array *array = container_of(map, struct bpf_array, map);u32 index = *(u32 *)key;
@@ -386,7 +386,7 @@ int bpf_percpu_array_update(struct bpf_map *map, void *key, void *value, }/* Called from syscall or from eBPF program */ -static int array_map_delete_elem (struct bpf_map *map,void *key) +static long array_map_delete_elem (struct bpf_map *map,void *key) {return -EINVAL ; }
@@ -686,8 +686,8 @@ static const struct bpf_iter_seq_info iter_seq_info = { .seq_priv_size = sizeof(struct bpf_iter_seq_array_map_info), }; -static int bpf_for_each_array_elem (struct bpf_map *map,bpf_callback_t callback_fn, -void *callback_ctx,u64 flags) +static long bpf_for_each_array_elem (struct bpf_map *map,bpf_callback_t callback_fn, +void *callback_ctx,u64 flags) {u32 i, key, num_elems =0 ;struct bpf_array *array;
@@ -847,7 +847,7 @@ int bpf_fd_array_map_update_elem(struct bpf_map *map, struct file *map_file,return 0 ; } -static int fd_array_map_delete_elem (struct bpf_map *map,void *key) +static long fd_array_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_array *array = container_of(map, struct bpf_array, map);void *old_ptr;
kernel/bpf/bloom_filter.c +6 -6
@@ -41,7 +41,7 @@ static u32 hash(struct bpf_bloom_filter *bloom, void *value,return h & bloom->bitset_mask; } -static int bloom_map_peek_elem (struct bpf_map *map,void *value) +static long bloom_map_peek_elem (struct bpf_map *map,void *value) {struct bpf_bloom_filter *bloom = container_of(map, struct bpf_bloom_filter, map);
@@ -56,7 +56,7 @@ static int bloom_map_peek_elem(struct bpf_map *map, void *value)return 0 ; } -static int bloom_map_push_elem (struct bpf_map *map,void *value,u64 flags) +static long bloom_map_push_elem (struct bpf_map *map,void *value,u64 flags) {struct bpf_bloom_filter *bloom = container_of(map, struct bpf_bloom_filter, map);
@@ -73,12 +73,12 @@ static int bloom_map_push_elem(struct bpf_map *map, void *value, u64 flags)return 0 ; } -static int bloom_map_pop_elem (struct bpf_map *map,void *value) +static long bloom_map_pop_elem (struct bpf_map *map,void *value) {return -EOPNOTSUPP ; } -static int bloom_map_delete_elem (struct bpf_map *map,void *value) +static long bloom_map_delete_elem (struct bpf_map *map,void *value) {return -EOPNOTSUPP ; }
@@ -177,8 +177,8 @@ static void *bloom_map_lookup_elem(struct bpf_map *map, void *key)return ERR_PTR (-EINVAL ); } -static int bloom_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 flags) +static long bloom_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 flags) {/* The eBPF program should use map_push_elem instead */ return -EINVAL ;
kernel/bpf/bpf_cgrp_storage.c +3 -3
@@ -100,8 +100,8 @@ static void *bpf_cgrp_storage_lookup_elem(struct bpf_map *map, void *key)return sdata ? sdata->data :NULL ; } -static int bpf_cgrp_storage_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long bpf_cgrp_storage_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {struct bpf_local_storage_data *sdata;struct cgroup *cgroup;
@@ -132,7 +132,7 @@ static int cgroup_storage_delete(struct cgroup *cgroup, struct bpf_map *map)return 0 ; } -static int bpf_cgrp_storage_delete_elem (struct bpf_map *map,void *key) +static long bpf_cgrp_storage_delete_elem (struct bpf_map *map,void *key) {struct cgroup *cgroup;int err, fd;
kernel/bpf/bpf_inode_storage.c +3 -3
@@ -97,8 +97,8 @@ static void *bpf_fd_inode_storage_lookup_elem(struct bpf_map *map, void *key)return sdata ? sdata->data :NULL ; } -static int bpf_fd_inode_storage_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long bpf_fd_inode_storage_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {struct bpf_local_storage_data *sdata;struct file *f;
@@ -133,7 +133,7 @@ static int inode_storage_delete(struct inode *inode, struct bpf_map *map)return 0 ; } -static int bpf_fd_inode_storage_delete_elem (struct bpf_map *map,void *key) +static long bpf_fd_inode_storage_delete_elem (struct bpf_map *map,void *key) {struct file *f;int fd, err;
kernel/bpf/bpf_struct_ops.c +3 -3
@@ -349,8 +349,8 @@ int bpf_struct_ops_prepare_trampoline(struct bpf_tramp_links *tlinks, model, flags, tlinks, NULL); } -static int bpf_struct_ops_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 flags) +static long bpf_struct_ops_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 flags) {struct bpf_struct_ops_map *st_map = (struct bpf_struct_ops_map *)map;const struct bpf_struct_ops *st_ops = st_map->st_ops;
@@ -524,7 +524,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,return err; } -static int bpf_struct_ops_map_delete_elem (struct bpf_map *map,void *key) +static long bpf_struct_ops_map_delete_elem (struct bpf_map *map,void *key) {enum bpf_struct_ops_state prev_state;struct bpf_struct_ops_map *st_map;
kernel/bpf/bpf_task_storage.c +3 -3
@@ -127,8 +127,8 @@ static void *bpf_pid_task_storage_lookup_elem(struct bpf_map *map, void *key)return ERR_PTR (err); } -static int bpf_pid_task_storage_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long bpf_pid_task_storage_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {struct bpf_local_storage_data *sdata;struct task_struct *task;
@@ -180,7 +180,7 @@ static int task_storage_delete(struct task_struct *task, struct bpf_map *map,return 0 ; } -static int bpf_pid_task_storage_delete_elem (struct bpf_map *map,void *key) +static long bpf_pid_task_storage_delete_elem (struct bpf_map *map,void *key) {struct task_struct *task;unsigned int f_flags;
kernel/bpf/cpumap.c +4 -4
@@ -540,7 +540,7 @@ static void __cpu_map_entry_replace(struct bpf_cpu_map *cmap, } } -static int cpu_map_delete_elem (struct bpf_map *map,void *key) +static long cpu_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);u32 key_cpu = *(u32 *)key;
@@ -553,8 +553,8 @@ static int cpu_map_delete_elem(struct bpf_map *map, void *key)return 0 ; } -static int cpu_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long cpu_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) { struct bpf_cpu_map *cmap = container_of(map, struct bpf_cpu_map, map);struct bpf_cpumap_val cpumap_value = {};
@@ -667,7 +667,7 @@ static int cpu_map_get_next_key(struct bpf_map *map, void *key, void *next_key)return 0 ; } -static int cpu_map_redirect (struct bpf_map *map,u64 index,u64 flags) +static long cpu_map_redirect (struct bpf_map *map,u64 index,u64 flags) {return __bpf_xdp_redirect_map (map, index, flags,0 , __cpu_map_lookup_elem);
kernel/bpf/devmap.c +12 -12
@@ -809,7 +809,7 @@ static void __dev_map_entry_free(struct rcu_head *rcu)kfree (dev); } -static int dev_map_delete_elem (struct bpf_map *map,void *key) +static long dev_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);struct bpf_dtab_netdev *old_dev;
@@ -824,7 +824,7 @@ static int dev_map_delete_elem(struct bpf_map *map, void *key)return 0 ; } -static int dev_map_hash_delete_elem (struct bpf_map *map,void *key) +static long dev_map_hash_delete_elem (struct bpf_map *map,void *key) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);struct bpf_dtab_netdev *old_dev;
@@ -895,8 +895,8 @@ static struct bpf_dtab_netdev *__dev_map_alloc_node(struct net *net,return ERR_PTR (-EINVAL ); } -static int __dev_map_update_elem (struct net *net,struct bpf_map *map, -void *key,void *value,u64 map_flags) +static long __dev_map_update_elem (struct net *net,struct bpf_map *map, +void *key,void *value,u64 map_flags) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);struct bpf_dtab_netdev *dev, *old_dev;
@@ -935,15 +935,15 @@ static int __dev_map_update_elem(struct net *net, struct bpf_map *map,return 0 ; } -static int dev_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long dev_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) {return __dev_map_update_elem (current->nsproxy->net_ns, map, key, value, map_flags); } -static int __dev_map_hash_update_elem (struct net *net,struct bpf_map *map, -void *key,void *value,u64 map_flags) +static long __dev_map_hash_update_elem (struct net *net,struct bpf_map *map, +void *key,void *value,u64 map_flags) { struct bpf_dtab *dtab = container_of(map, struct bpf_dtab, map);struct bpf_dtab_netdev *dev, *old_dev;
@@ -995,21 +995,21 @@ static int __dev_map_hash_update_elem(struct net *net, struct bpf_map *map,return err; } -static int dev_map_hash_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long dev_map_hash_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) {return __dev_map_hash_update_elem (current->nsproxy->net_ns, map, key, value, map_flags); } -static int dev_map_redirect (struct bpf_map *map,u64 ifindex,u64 flags) +static long dev_map_redirect (struct bpf_map *map,u64 ifindex,u64 flags) {return __bpf_xdp_redirect_map (map, ifindex, flags,BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS , __dev_map_lookup_elem); } -static int dev_hash_map_redirect (struct bpf_map *map,u64 ifindex,u64 flags) +static long dev_hash_map_redirect (struct bpf_map *map,u64 ifindex,u64 flags) { return __bpf_xdp_redirect_map(map, ifindex, flags, BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS,
kernel/bpf/hashtab.c +18 -18
@@ -1057,8 +1057,8 @@ static int check_flags(struct bpf_htab *htab, struct htab_elem *l_old, }/* Called from syscall or from eBPF program */ -static int htab_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long htab_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct htab_elem *l_new =NULL , *l_old;
@@ -1159,8 +1159,8 @@ static void htab_lru_push_free(struct bpf_htab *htab, struct htab_elem *elem)bpf_lru_push_free (&htab->lru, &elem->lru_node); } -static int htab_lru_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long htab_lru_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct htab_elem *l_new, *l_old =NULL ;
@@ -1226,9 +1226,9 @@ static int htab_lru_map_update_elem(struct bpf_map *map, void *key, void *value,return ret; } -static int __htab_percpu_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags, -bool onallcpus) +static long __htab_percpu_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags, +bool onallcpus) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct htab_elem *l_new =NULL , *l_old;
@@ -1281,9 +1281,9 @@ static int __htab_percpu_map_update_elem(struct bpf_map *map, void *key,return ret; } -static int __htab_lru_percpu_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags, -bool onallcpus) +static long __htab_lru_percpu_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags, +bool onallcpus) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct htab_elem *l_new =NULL , *l_old;
@@ -1348,21 +1348,21 @@ static int __htab_lru_percpu_map_update_elem(struct bpf_map *map, void *key,return ret; } -static int htab_percpu_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long htab_percpu_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {return __htab_percpu_map_update_elem (map, key, value, map_flags, false); } -static int htab_lru_percpu_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long htab_lru_percpu_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {return __htab_lru_percpu_map_update_elem (map, key, value, map_flags, false); }/* Called from syscall or from eBPF program */ -static int htab_map_delete_elem (struct bpf_map *map,void *key) +static long htab_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct hlist_nulls_head *head;
@@ -1398,7 +1398,7 @@ static int htab_map_delete_elem(struct bpf_map *map, void *key)return ret; } -static int htab_lru_map_delete_elem (struct bpf_map *map,void *key) +static long htab_lru_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct hlist_nulls_head *head;
@@ -2119,8 +2119,8 @@ static const struct bpf_iter_seq_info iter_seq_info = { .seq_priv_size = sizeof(struct bpf_iter_seq_hash_map_info), }; -static int bpf_for_each_hash_elem (struct bpf_map *map,bpf_callback_t callback_fn, -void *callback_ctx,u64 flags) +static long bpf_for_each_hash_elem (struct bpf_map *map,bpf_callback_t callback_fn, +void *callback_ctx,u64 flags) { struct bpf_htab *htab = container_of(map, struct bpf_htab, map);struct hlist_nulls_head *head;
kernel/bpf/local_storage.c +3 -3
@@ -141,8 +141,8 @@ static void *cgroup_storage_lookup_elem(struct bpf_map *_map, void *key)return &READ_ONCE (storage->buf)->data[0 ]; } -static int cgroup_storage_update_elem (struct bpf_map *map,void *key, -void *value,u64 flags) +static long cgroup_storage_update_elem (struct bpf_map *map,void *key, +void *value,u64 flags) {struct bpf_cgroup_storage *storage;struct bpf_storage_buffer *new;
@@ -348,7 +348,7 @@ static void cgroup_storage_map_free(struct bpf_map *_map)bpf_map_area_free (map); } -static int cgroup_storage_delete_elem (struct bpf_map *map,void *key) +static long cgroup_storage_delete_elem (struct bpf_map *map,void *key) {return -EINVAL ; }
kernel/bpf/lpm_trie.c +3 -3
@@ -300,8 +300,8 @@ static struct lpm_trie_node *lpm_trie_node_alloc(const struct lpm_trie *trie, }/* Called from syscall or from eBPF program */ -static int trie_update_elem (struct bpf_map *map, -void *_key,void *value,u64 flags) +static long trie_update_elem (struct bpf_map *map, +void *_key,void *value,u64 flags) { struct lpm_trie *trie = container_of(map, struct lpm_trie, map);struct lpm_trie_node *node, *im_node =NULL , *new_node =NULL ;
@@ -431,7 +431,7 @@ static int trie_update_elem(struct bpf_map *map, }/* Called from syscall or from eBPF program */ -static int trie_delete_elem (struct bpf_map *map,void *_key) +static long trie_delete_elem (struct bpf_map *map,void *_key) { struct lpm_trie *trie = container_of(map, struct lpm_trie, map);struct bpf_lpm_trie_key *key = _key;
kernel/bpf/queue_stack_maps.c +11 -11
@@ -95,7 +95,7 @@ static void queue_stack_map_free(struct bpf_map *map)bpf_map_area_free (qs); } -static int __queue_map_get (struct bpf_map *map,void *value,bool delete) +static long __queue_map_get (struct bpf_map *map,void *value,bool delete) {struct bpf_queue_stack *qs =bpf_queue_stack (map);unsigned long flags;
@@ -124,7 +124,7 @@ static int __queue_map_get(struct bpf_map *map, void *value, bool delete) } -static int __stack_map_get (struct bpf_map *map,void *value,bool delete) +static long __stack_map_get (struct bpf_map *map,void *value,bool delete) {struct bpf_queue_stack *qs =bpf_queue_stack (map);unsigned long flags;
@@ -156,32 +156,32 @@ static int __stack_map_get(struct bpf_map *map, void *value, bool delete) }/* Called from syscall or from eBPF program */ -static int queue_map_peek_elem (struct bpf_map *map,void *value) +static long queue_map_peek_elem (struct bpf_map *map,void *value) {return __queue_map_get (map, value, false); }/* Called from syscall or from eBPF program */ -static int stack_map_peek_elem (struct bpf_map *map,void *value) +static long stack_map_peek_elem (struct bpf_map *map,void *value) {return __stack_map_get (map, value, false); }/* Called from syscall or from eBPF program */ -static int queue_map_pop_elem (struct bpf_map *map,void *value) +static long queue_map_pop_elem (struct bpf_map *map,void *value) {return __queue_map_get (map, value, true); }/* Called from syscall or from eBPF program */ -static int stack_map_pop_elem (struct bpf_map *map,void *value) +static long stack_map_pop_elem (struct bpf_map *map,void *value) {return __stack_map_get (map, value, true); }/* Called from syscall or from eBPF program */ -static int queue_stack_map_push_elem (struct bpf_map *map,void *value, -u64 flags) +static long queue_stack_map_push_elem (struct bpf_map *map,void *value, +u64 flags) {struct bpf_queue_stack *qs =bpf_queue_stack (map);unsigned long irq_flags;
@@ -227,14 +227,14 @@ static void *queue_stack_map_lookup_elem(struct bpf_map *map, void *key) }/* Called from syscall or from eBPF program */ -static int queue_stack_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 flags) +static long queue_stack_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 flags) {return -EINVAL ; }/* Called from syscall or from eBPF program */ -static int queue_stack_map_delete_elem (struct bpf_map *map,void *key) +static long queue_stack_map_delete_elem (struct bpf_map *map,void *key) {return -EINVAL ; }
kernel/bpf/reuseport_array.c +1 -1
@@ -59,7 +59,7 @@ static void *reuseport_array_lookup_elem(struct bpf_map *map, void *key) }/* Called from syscall only */ -static int reuseport_array_delete_elem (struct bpf_map *map,void *key) +static long reuseport_array_delete_elem (struct bpf_map *map,void *key) {struct reuseport_array *array =reuseport_array (map);u32 index = *(u32 *)key;
kernel/bpf/ringbuf.c +3 -3
@@ -241,13 +241,13 @@ static void *ringbuf_map_lookup_elem(struct bpf_map *map, void *key)return ERR_PTR (-ENOTSUPP ); } -static int ringbuf_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 flags) +static long ringbuf_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 flags) {return -ENOTSUPP ; } -static int ringbuf_map_delete_elem (struct bpf_map *map,void *key) +static long ringbuf_map_delete_elem (struct bpf_map *map,void *key) {return -ENOTSUPP ; }
kernel/bpf/stackmap.c +3 -3
@@ -618,14 +618,14 @@ static int stack_map_get_next_key(struct bpf_map *map, void *key,return 0 ; } -static int stack_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long stack_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) {return -EINVAL ; }/* Called from syscall or from eBPF program */ -static int stack_map_delete_elem (struct bpf_map *map,void *key) +static long stack_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map);struct stack_map_bucket *old_bucket;
kernel/bpf/verifier.c +7 -7
@@ -16678,21 +16678,21 @@ static int do_misc_fixups(struct bpf_verifier_env *env)BUILD_BUG_ON (!__same_type (ops->map_lookup_elem, (void *(*)(struct bpf_map *map,void *key))NULL ));BUILD_BUG_ON (!__same_type (ops->map_delete_elem, - (int (*)(struct bpf_map *map,void *key))NULL )); + (long (*)(struct bpf_map *map,void *key))NULL ));BUILD_BUG_ON (!__same_type (ops->map_update_elem, - (int (*)(struct bpf_map *map,void *key,void *value, + (long (*)(struct bpf_map *map,void *key,void *value,u64 flags))NULL ));BUILD_BUG_ON (!__same_type (ops->map_push_elem, - (int (*)(struct bpf_map *map,void *value, + (long (*)(struct bpf_map *map,void *value,u64 flags))NULL ));BUILD_BUG_ON (!__same_type (ops->map_pop_elem, - (int (*)(struct bpf_map *map,void *value))NULL )); + (long (*)(struct bpf_map *map,void *value))NULL ));BUILD_BUG_ON (!__same_type (ops->map_peek_elem, - (int (*)(struct bpf_map *map,void *value))NULL )); + (long (*)(struct bpf_map *map,void *value))NULL ));BUILD_BUG_ON (!__same_type (ops->map_redirect, - (int (*)(struct bpf_map *map,u64 index,u64 flags))NULL )); + (long (*)(struct bpf_map *map,u64 index,u64 flags))NULL ));BUILD_BUG_ON (!__same_type (ops->map_for_each_callback, - (int (*)(struct bpf_map *map, + (long (*)(struct bpf_map *map,bpf_callback_t callback_fn,void *callback_ctx,u64 flags))NULL ));
net/core/bpf_sk_storage.c +3 -3
@@ -100,8 +100,8 @@ static void *bpf_fd_sk_storage_lookup_elem(struct bpf_map *map, void *key)return ERR_PTR (err); } -static int bpf_fd_sk_storage_update_elem (struct bpf_map *map,void *key, -void *value,u64 map_flags) +static long bpf_fd_sk_storage_update_elem (struct bpf_map *map,void *key, +void *value,u64 map_flags) {struct bpf_local_storage_data *sdata;struct socket *sock;
@@ -120,7 +120,7 @@ static int bpf_fd_sk_storage_update_elem(struct bpf_map *map, void *key,return err; } -static int bpf_fd_sk_storage_delete_elem (struct bpf_map *map,void *key) +static long bpf_fd_sk_storage_delete_elem (struct bpf_map *map,void *key) {struct socket *sock;int fd, err;
net/core/sock_map.c +4 -4
@@ -437,7 +437,7 @@ static void sock_map_delete_from_link(struct bpf_map *map, struct sock *sk,__sock_map_delete (stab, sk, link_raw); } -static int sock_map_delete_elem (struct bpf_map *map,void *key) +static long sock_map_delete_elem (struct bpf_map *map,void *key) { struct bpf_stab *stab = container_of(map, struct bpf_stab, map);u32 i = *(u32 *)key;
@@ -587,8 +587,8 @@ int sock_map_update_elem_sys(struct bpf_map *map, void *key, void *value,return ret; } -static int sock_map_update_elem (struct bpf_map *map,void *key, -void *value,u64 flags) +static long sock_map_update_elem (struct bpf_map *map,void *key, +void *value,u64 flags) {struct sock *sk = (struct sock *)value;int ret;
@@ -916,7 +916,7 @@ static void sock_hash_delete_from_link(struct bpf_map *map, struct sock *sk,raw_spin_unlock_bh (&bucket->lock); } -static int sock_hash_delete_elem (struct bpf_map *map,void *key) +static long sock_hash_delete_elem (struct bpf_map *map,void *key) { struct bpf_shtab *htab = container_of(map, struct bpf_shtab, map);u32 hash, key_size = map->key_size;
net/xdp/xskmap.c +4 -4
@@ -150,8 +150,8 @@ static void *xsk_map_lookup_elem_sys_only(struct bpf_map *map, void *key)return ERR_PTR (-EOPNOTSUPP ); } -static int xsk_map_update_elem (struct bpf_map *map,void *key,void *value, -u64 map_flags) +static long xsk_map_update_elem (struct bpf_map *map,void *key,void *value, +u64 map_flags) { struct xsk_map *m = container_of(map, struct xsk_map, map);struct xdp_sock __rcu **map_entry;
@@ -211,7 +211,7 @@ static int xsk_map_update_elem(struct bpf_map *map, void *key, void *value,return err; } -static int xsk_map_delete_elem (struct bpf_map *map,void *key) +static long xsk_map_delete_elem (struct bpf_map *map,void *key) { struct xsk_map *m = container_of(map, struct xsk_map, map);struct xdp_sock __rcu **map_entry;
@@ -231,7 +231,7 @@ static int xsk_map_delete_elem(struct bpf_map *map, void *key)return 0 ; } -static int xsk_map_redirect (struct bpf_map *map,u64 index,u64 flags) +static long xsk_map_redirect (struct bpf_map *map,u64 index,u64 flags) {return __bpf_xdp_redirect_map (map, index, flags,0 , __xsk_map_lookup_elem);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 360/694 bpf: Fix __reg_bound_offset 64->32 var_off subreg propagation
In reply to Greg Kroah-HartmanFrom: Daniel Borkmann <[email protected]>
[ Upstream commit 7be14c1c9030f73cc18b4ff23b78a0a081f16188 ]
Xu reports that after commit 3f50f132d840 ("bpf: Verifier, do explicit ALU32 bounds tracking"), the following BPF program is rejected by the verifier:
0: (61) r2 = *(u32 *)(r1 +0) ; R2_w=pkt(off=0,r=0,imm=0)
1: (61) r3 = *(u32 *)(r1 +4) ; R3_w=pkt_end(off=0,imm=0)
2: (bf) r1 = r2
3: (07) r1 += 1
4: (2d) if r1 > r3 goto pc+8
5: (71) r1 = *(u8 *)(r2 +0) ; R1_w=scalar(umax=255,var_off=(0x0; 0xff))
6: (18) r0 = 0x7fffffffffffff10
8: (0f) r1 += r0 ; R1_w=scalar(umin=0x7fffffffffffff10,umax=0x800000000000000f)
9: (18) r0 = 0x8000000000000000
11: (07) r0 += 1
12: (ad) if r0 < r1 goto pc-2
13: (b7) r0 = 0
14: (95) exit
And the verifier log says:
func#0 @0
0: R1=ctx(off=0,imm=0) R10=fp0
0: (61) r2 = *(u32 *)(r1 +0) ; R1=ctx(off=0,imm=0) R2_w=pkt(off=0,r=0,imm=0) 1: (61) r3 = *(u32 *)(r1 +4) ; R1=ctx(off=0,imm=0) R3_w=pkt_end(off=0,imm=0) 2: (bf) r1 = r2 ; R1_w=pkt(off=0,r=0,imm=0) R2_w=pkt(off=0,r=0,imm=0) 3: (07) r1 += 1 ; R1_w=pkt(off=1,r=0,imm=0) 4: (2d) if r1 > r3 goto pc+8 ; R1_w=pkt(off=1,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) 5: (71) r1 = *(u8 *)(r2 +0) ; R1_w=scalar(umax=255,var_off=(0x0; 0xff)) R2_w=pkt(off=0,r=1,imm=0) 6: (18) r0 = 0x7fffffffffffff10 ; R0_w=9223372036854775568 8: (0f) r1 += r0 ; R0_w=9223372036854775568 R1_w=scalar(umin=9223372036854775568,umax=9223372036854775823,s32_min=-240,s32_max=15) 9: (18) r0 = 0x8000000000000000 ; R0_w=-9223372036854775808 11: (07) r0 += 1 ; R0_w=-9223372036854775807 12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775807 R1_w=scalar(umin=9223372036854775568,umax=9223372036854775809) 13: (b7) r0 = 0 ; R0_w=0
14: (95) exit
from 12 to 11: R0_w=-9223372036854775807 R1_w=scalar(umin=9223372036854775810,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff)) R2_w=pkt(off=0,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775806
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775806 R1_w=scalar(umin=9223372036854775810,umax=9223372036854775810,var_off=(0x8000000000000000; 0xffffffff))
13: safe
[...]
from 12 to 11: R0_w=-9223372036854775795 R1=scalar(umin=9223372036854775822,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff)) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775794
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775794 R1=scalar(umin=9223372036854775822,umax=9223372036854775822,var_off=(0x8000000000000000; 0xffffffff))
13: safe
from 12 to 11: R0_w=-9223372036854775794 R1=scalar(umin=9223372036854775823,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff)) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775793
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775793 R1=scalar(umin=9223372036854775823,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff))
13: safe
from 12 to 11: R0_w=-9223372036854775793 R1=scalar(umin=9223372036854775824,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff)) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775792
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775792 R1=scalar(umin=9223372036854775824,umax=9223372036854775823,var_off=(0x8000000000000000; 0xffffffff))
13: safe
[...]
The 64bit umin=9223372036854775810 bound continuously bumps by +1 while umax=9223372036854775823 stays as-is until the verifier complexity limit is reached and the program gets finally rejected. During this simulation, the umin also eventually surpasses umax. Looking at the first 'from 12 to 11' output line from the loop, R1 has the following state:
R1_w=scalar(umin=0x8000000000000002 (9223372036854775810),
umax=0x800000000000000f (9223372036854775823),
var_off=(0x8000000000000000;
0xffffffff))The var_off has technically not an inconsistent state but it's very imprecise and far off surpassing 64bit umax bounds whereas the expected output with refined known bits in var_off should have been like:
R1_w=scalar(umin=0x8000000000000002 (9223372036854775810),
umax=0x800000000000000f (9223372036854775823),
var_off=(0x8000000000000000;
0xf))In the above log, var_off stays as var_off=(0x8000000000000000; 0xffffffff) and does not converge into a narrower mask where more bits become known, eventually transforming R1 into a constant upon umin=9223372036854775823, umax=9223372036854775823 case where the verifier would have terminated and let the program pass.
The __reg_combine_64_into_32() marks the subregister unknown and propagates 64bit {s,u}min/{s,u}max bounds to their 32bit equivalents iff they are within the 32bit universe. The question came up whether __reg_combine_64_into_32() should special case the situation that when 64bit {s,u}min bounds have the same value as 64bit {s,u}max bounds to then assign the latter as well to the 32bit reg->{s,u}32_{min,max}_value. As can be seen from the above example however, that is just /one/ special case and not a /generic/ solution given above example would still not be addressed this way and remain at an imprecise var_off=(0x8000000000000000; 0xffffffff).
The improvement is needed in __reg_bound_offset() to refine var32_off with the updated var64_off instead of the prior reg->var_off. The reg_bounds_sync() code first refines information about the register's min/max bounds via __update_reg_bounds() from the current var_off, then in __reg_deduce_bounds() from sign bit and with the potentially learned bits from bounds it'll update the var_off tnum in __reg_bound_offset(). For example, intersecting with the old var_off might have improved bounds slightly, e.g. if umax was 0x7f...f and var_off was (0; 0xf...fc), then new var_off will then result in (0; 0x7f...fc). The intersected var64_off holds then the universe which is a superset of var32_off. The point for the latter is not to broaden, but to further refine known bits based on the intersection of var_off with 32 bit bounds, so that we later construct the final var_off from upper and lower 32 bits. The final __update_reg_bounds() can then potentially still slightly refine bounds if more bits became known from the new var_off.
After the improvement, we can see R1 converging successively:
func#0 @0
0: R1=ctx(off=0,imm=0) R10=fp0
0: (61) r2 = *(u32 *)(r1 +0) ; R1=ctx(off=0,imm=0) R2_w=pkt(off=0,r=0,imm=0) 1: (61) r3 = *(u32 *)(r1 +4) ; R1=ctx(off=0,imm=0) R3_w=pkt_end(off=0,imm=0) 2: (bf) r1 = r2 ; R1_w=pkt(off=0,r=0,imm=0) R2_w=pkt(off=0,r=0,imm=0) 3: (07) r1 += 1 ; R1_w=pkt(off=1,r=0,imm=0) 4: (2d) if r1 > r3 goto pc+8 ; R1_w=pkt(off=1,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) 5: (71) r1 = *(u8 *)(r2 +0) ; R1_w=scalar(umax=255,var_off=(0x0; 0xff)) R2_w=pkt(off=0,r=1,imm=0) 6: (18) r0 = 0x7fffffffffffff10 ; R0_w=9223372036854775568 8: (0f) r1 += r0 ; R0_w=9223372036854775568 R1_w=scalar(umin=9223372036854775568,umax=9223372036854775823,s32_min=-240,s32_max=15) 9: (18) r0 = 0x8000000000000000 ; R0_w=-9223372036854775808 11: (07) r0 += 1 ; R0_w=-9223372036854775807 12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775807 R1_w=scalar(umin=9223372036854775568,umax=9223372036854775809) 13: (b7) r0 = 0 ; R0_w=0
14: (95) exit
from 12 to 11: R0_w=-9223372036854775807 R1_w=scalar(umin=9223372036854775810,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2_w=pkt(off=0,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775806
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775806 R1_w=-9223372036854775806
13: safe
from 12 to 11: R0_w=-9223372036854775806 R1_w=scalar(umin=9223372036854775811,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2_w=pkt(off=0,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775805
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775805 R1_w=-9223372036854775805
13: safe
[...]
from 12 to 11: R0_w=-9223372036854775798 R1=scalar(umin=9223372036854775819,umax=9223372036854775823,var_off=(0x8000000000000008; 0x7),s32_min=8,s32_max=15,u32_min=8,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775797
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775797 R1=-9223372036854775797
13: safe
from 12 to 11: R0_w=-9223372036854775797 R1=scalar(umin=9223372036854775820,umax=9223372036854775823,var_off=(0x800000000000000c; 0x3),s32_min=12,s32_max=15,u32_min=12,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775796
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775796 R1=-9223372036854775796
13: safe
from 12 to 11: R0_w=-9223372036854775796 R1=scalar(umin=9223372036854775821,umax=9223372036854775823,var_off=(0x800000000000000c; 0x3),s32_min=12,s32_max=15,u32_min=12,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775795
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775795 R1=-9223372036854775795
13: safe
from 12 to 11: R0_w=-9223372036854775795 R1=scalar(umin=9223372036854775822,umax=9223372036854775823,var_off=(0x800000000000000e; 0x1),s32_min=14,s32_max=15,u32_min=14,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775794
12: (ad) if r0 < r1 goto pc-2 ; R0_w=-9223372036854775794 R1=-9223372036854775794
13: safe
from 12 to 11: R0_w=-9223372036854775794 R1=-9223372036854775793 R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0
11: (07) r0 += 1 ; R0_w=-9223372036854775793
12: (ad) if r0 < r1 goto pc-2
last_idx 12 first_idx 12
parent didn't have regs=1 stack=0 marks: R0_rw=P-9223372036854775801 R1_r=scalar(umin=9223372036854775815,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0 last_idx 11 first_idx 11
regs=1 stack=0 before 11: (07) r0 += 1
parent didn't have regs=1 stack=0 marks: R0_rw=P-9223372036854775805 R1_rw=scalar(umin=9223372036854775812,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2_w=pkt(off=0,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) R10=fp0 last_idx 12 first_idx 0
regs=1 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=1 stack=0 before 11: (07) r0 += 1
regs=1 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=1 stack=0 before 11: (07) r0 += 1
regs=1 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=1 stack=0 before 11: (07) r0 += 1
regs=1 stack=0 before 9: (18) r0 = 0x8000000000000000
last_idx 12 first_idx 12
parent didn't have regs=2 stack=0 marks: R0_rw=P-9223372036854775801 R1_r=Pscalar(umin=9223372036854775815,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2=pkt(off=0,r=1,imm=0) R3=pkt_end(off=0,imm=0) R10=fp0 last_idx 11 first_idx 11
regs=2 stack=0 before 11: (07) r0 += 1
parent didn't have regs=2 stack=0 marks: R0_rw=P-9223372036854775805 R1_rw=Pscalar(umin=9223372036854775812,umax=9223372036854775823,var_off=(0x8000000000000000; 0xf),s32_min=0,s32_max=15,u32_max=15) R2_w=pkt(off=0,r=1,imm=0) R3_w=pkt_end(off=0,imm=0) R10=fp0 last_idx 12 first_idx 0
regs=2 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=2 stack=0 before 11: (07) r0 += 1
regs=2 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=2 stack=0 before 11: (07) r0 += 1
regs=2 stack=0 before 12: (ad) if r0 < r1 goto pc-2
regs=2 stack=0 before 11: (07) r0 += 1
regs=2 stack=0 before 9: (18) r0 = 0x8000000000000000
regs=2 stack=0 before 8: (0f) r1 += r0
regs=3 stack=0 before 6: (18) r0 = 0x7fffffffffffff10
regs=2 stack=0 before 5: (71) r1 = *(u8 *)(r2 +0)
13: safe
from 4 to 13: safe
verification time 322 usec
stack depth 0
processed 56 insns (limit 1000000) max_states_per_insn 1 total_states 3 peak_states 3 mark_read 1
This also fixes up a test case along with this improvement where we match on the verifier log. The updated log now has a refined var_off, too.
--- kernel/bpf/verifier.c | 6 +++--- tools/testing/selftests/bpf/prog_tests/align.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
kernel/bpf/verifier.c +3 -3
@@ -1823,9 +1823,9 @@ static void __reg_bound_offset(struct bpf_reg_state *reg)struct tnum var64_off =tnum_intersect (reg->var_off,tnum_range (reg->umin_value, reg->umax_value)); -struct tnum var32_off =tnum_intersect (tnum_subreg (reg->var_off), -tnum_range (reg->u32_min_value, - reg->u32_max_value)); +struct tnum var32_off =tnum_intersect (tnum_subreg (var64_off), +tnum_range (reg->u32_min_value, + reg->u32_max_value)); reg->var_off =tnum_or (tnum_clear_subreg (var64_off), var32_off); }
tools/testing/selftests/bpf/prog_tests/align.c +2 -2
@@ -575,14 +575,14 @@ static struct bpf_align_test tests[] = {/* New unknown value in R7 is (4n), >= 76 */ {14, "R7_w=scalar(umin=76,umax=1096,var_off=(0x0; 0x7fc))"},/* Adding it to packet pointer gives nice bounds again */ - {16, "R5_w=pkt(id=3,off=0,r=0,umin=2,umax=1082,var_off=(0x2; 0xfffffffc)"}, + {16, "R5_w=pkt(id=3,off=0,r=0,umin=2,umax=1082,var_off=(0x2; 0x7fc)"},/* At the time the word size load is performed from R5, * its total fixed offset is NET_IP_ALIGN + reg->off (0) * which is 2. Then the variable offset is (4n+2), so * the total offset is 4-byte aligned and meets the * load's requirements. */ - {20, "R5=pkt(id=3,off=0,r=4,umin=2,umax=1082,var_off=(0x2; 0xfffffffc)"}, + {20, "R5=pkt(id=3,off=0,r=4,umin=2,umax=1082,var_off=(0x2; 0x7fc)"}, }, }, };
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 361/694 scsi: target: Move sess cmd counter to new struct
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit becd9be6069e7b183c084f460f0eb363e43cc487 ]
iSCSI needs to wait on outstanding commands like how SRP and the FC/FCoE drivers do. It can't use target_stop_session() because for MCS support we can't stop the entire session during recovery because if other connections are OK then we want to be able to continue to execute I/O on them.
Move the per session cmd counters to a new struct so iSCSI can allocate them per connection. The xcopy code can also just not allocate in the future since it doesn't need to track commands.
Stable-dep-of: 395cee83d02d ("scsi: target: iscsit: Stop/wait on cmds during conn close")
--- drivers/target/target_core_tpg.c | 2 +- drivers/target/target_core_transport.c | 135 ++++++++++++++++------- include/target/iscsi/iscsi_target_core.h | 1 + include/target/target_core_base.h | 13 ++- 4 files changed, 107 insertions(+), 44 deletions(-)
drivers/target/target_core_tpg.c +1 -1
@@ -328,7 +328,7 @@ static void target_shutdown_sessions(struct se_node_acl *acl) restart:spin_lock_irqsave (&acl->nacl_sess_lock, flags);list_for_each_entry (sess, &acl->acl_sess_list, sess_acl_list) { -if (atomic_read (&sess->stopped)) +if (sess->cmd_cnt &&atomic_read (&sess->cmd_cnt->stopped))continue ;list_del_init (&sess->sess_acl_list);
drivers/target/target_core_transport.c +96 -39
201 lines not on this page · raw message
include/target/iscsi/iscsi_target_core.h +1 -0
@@ -600,6 +600,7 @@ struct iscsit_conn {struct iscsi_tpg_np *tpg_np;/* Pointer to parent session */ struct iscsit_session *sess; +struct target_cmd_counter *cmd_cnt;int bitmap_id;int rx_thread_active;struct task_struct *rx_thread;
include/target/target_core_base.h +9 -4
@@ -494,6 +494,7 @@ struct se_cmd {struct se_lun *se_lun;/* Only used for internal passthrough and legacy TCM fabric modules */ struct se_session *se_sess; +struct target_cmd_counter *cmd_cnt;struct se_tmr_req *se_tmr_req;struct llist_node se_cmd_list;struct completion *free_compl;
@@ -619,22 +620,26 @@ static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item) acl_fabric_stat_group); } -struct se_session { +struct target_cmd_counter { +struct percpu_ref refcnt; +wait_queue_head_t refcnt_wq; +struct completion stop_done;atomic_t stopped; +}; + +struct se_session {u64 sess_bin_isid;enum target_prot_op sup_prot_ops;enum target_prot_type sess_prot_type;struct se_node_acl *se_node_acl;struct se_portal_group *se_tpg;void *fabric_sess_ptr; -struct percpu_ref cmd_count;struct list_head sess_list;struct list_head sess_acl_list;spinlock_t sess_cmd_lock; -wait_queue_head_t cmd_count_wq; -struct completion stop_done;void *sess_cmd_map;struct sbitmap_queue sess_tag_pool; +struct target_cmd_counter *cmd_cnt; };struct se_device ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 362/694 scsi: target: Move cmd counter allocation
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit 4edba7e4a8f39112398d3cda94128a8e13a7d527 ]
iSCSI needs to allocate its cmd counter per connection for MCS support where we need to stop and wait on commands running on a connection instead of per session. This moves the cmd counter allocation to target_setup_session() which is used by drivers that need the stop+wait behavior per session.
xcopy doesn't need stop+wait at all, so we will be OK moving the cmd counter allocation outside of transport_init_session().
Stable-dep-of: 395cee83d02d ("scsi: target: iscsit: Stop/wait on cmds during conn close")
--- drivers/target/iscsi/iscsi_target_login.c | 10 +++++ drivers/target/target_core_internal.h | 1 - drivers/target/target_core_transport.c | 55 +++++++++++------------ drivers/target/target_core_xcopy.c | 15 +------ include/target/target_core_fabric.h | 4 +- 5 files changed, 42 insertions(+), 43 deletions(-)
drivers/target/iscsi/iscsi_target_login.c +10 -0
@@ -324,8 +324,18 @@ static int iscsi_login_zero_tsih_s1( goto free_ops; } +/* +* This is temp for iser. It will be moved to per conn in later +* patches for iscsi. +*/ + sess->se_sess->cmd_cnt =target_alloc_cmd_counter (); +if (!sess->se_sess->cmd_cnt) + goto free_se_sess; +return 0 ; +free_se_sess: +transport_free_session (sess->se_sess); free_ops:kfree (sess->sess_ops); free_id:
drivers/target/target_core_internal.h +0 -1
@@ -138,7 +138,6 @@ int init_se_kmem_caches(void);void release_se_kmem_caches (void );u32 scsi_get_new_index (scsi_index_t );void transport_subsystem_check_init (void ); -void transport_uninit_session (struct se_session *);unsigned char *transport_dump_cmd_direction (struct se_cmd *);void transport_dump_dev_state (struct se_device *,char *,int *); void transport_dump_dev_info(struct se_device *, struct se_lun *,
drivers/target/target_core_transport.c +27 -28
126 lines not on this page · raw message
drivers/target/target_core_xcopy.c +2 -13
@@ -461,8 +461,6 @@ static const struct target_core_fabric_ops xcopy_pt_tfo = {int target_xcopy_setup_pt (void ) { -int ret; - xcopy_wq =alloc_workqueue ("xcopy_wq" ,WQ_MEM_RECLAIM ,0 );if (!xcopy_wq) {pr_err ("Unable to allocate xcopy_wq\n" );
@@ -479,9 +477,7 @@ int target_xcopy_setup_pt(void)INIT_LIST_HEAD (&xcopy_pt_nacl.acl_list);INIT_LIST_HEAD (&xcopy_pt_nacl.acl_sess_list);memset (&xcopy_pt_sess,0 ,sizeof (struct se_session )); - ret =transport_init_session (&xcopy_pt_sess); -if (ret <0 ) - goto destroy_wq; +transport_init_session (&xcopy_pt_sess); xcopy_pt_nacl.se_tpg = &xcopy_pt_tpg; xcopy_pt_nacl.nacl_sess = &xcopy_pt_sess;
@@ -490,19 +486,12 @@ int target_xcopy_setup_pt(void) xcopy_pt_sess.se_node_acl = &xcopy_pt_nacl;return 0 ; - -destroy_wq: -destroy_workqueue (xcopy_wq); - xcopy_wq =NULL ; -return ret; }void target_xcopy_release_pt (void ) { -if (xcopy_wq) { +if (xcopy_wq)destroy_workqueue (xcopy_wq); -transport_uninit_session (&xcopy_pt_sess); - } }/*
include/target/target_core_fabric.h +3 -1
@@ -133,7 +133,9 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *));void target_remove_session (struct se_session *); -int transport_init_session (struct se_session *se_sess); +struct target_cmd_counter *target_alloc_cmd_counter (void ); + +void transport_init_session (struct se_session *se_sess);struct se_session *transport_alloc_session (enum target_prot_op );int transport_alloc_session_tags (struct se_session *,unsigned int ,unsigned int );
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 363/694 scsi: target: Pass in cmd counter to use during cmd setup
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit 8e288be8606ad87c1726618eacfb8fbd3ab4b806 ]
Allow target_get_sess_cmd() users to pass in the cmd counter they want to use. Right now we pass in the session's cmd counter but in a subsequent commit iSCSI will switch from per session to per conn.
Stable-dep-of: 395cee83d02d ("scsi: target: iscsit: Stop/wait on cmds during conn close")
--- drivers/target/iscsi/iscsi_target.c | 10 +++++---- drivers/target/target_core_transport.c | 28 ++++++++++++-------------- drivers/target/target_core_xcopy.c | 8 ++++---- drivers/usb/gadget/function/f_tcm.c | 4 ++-- include/target/target_core_fabric.h | 8 +++++--- 5 files changed, 30 insertions(+), 28 deletions(-)
drivers/target/iscsi/iscsi_target.c +6 -4
@@ -1190,9 +1190,10 @@ int iscsit_setup_scsi_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,* Initialize struct se_cmd descriptor from target_core_mod infrastructure */ __target_init_cmd (&cmd->se_cmd, &iscsi_ops, - conn->sess->se_sess,be32_to_cpu (hdr->data_length), - cmd->data_direction, sam_task_attr, - cmd->sense_buffer +2 ,scsilun_to_int (&hdr->lun)); + conn->sess->se_sess,be32_to_cpu (hdr->data_length), + cmd->data_direction, sam_task_attr, + cmd->sense_buffer +2 ,scsilun_to_int (&hdr->lun), + conn->sess->se_sess->cmd_cnt); pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -2055,7 +2056,8 @@ iscsit_handle_task_mgt_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd,__target_init_cmd (&cmd->se_cmd, &iscsi_ops, conn->sess->se_sess,0 ,DMA_NONE ,TCM_SIMPLE_TAG , cmd->sense_buffer +2 , -scsilun_to_int (&hdr->lun)); +scsilun_to_int (&hdr->lun), + conn->sess->se_sess->cmd_cnt);target_get_sess_cmd (&cmd->se_cmd, true);
drivers/target/target_core_transport.c +13 -15
@@ -1441,14 +1441,12 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)* * Preserves the value of @cmd->tag. */ -void __target_init_cmd ( -struct se_cmd *cmd, -const struct target_core_fabric_ops *tfo, -struct se_session *se_sess, -u32 data_length, -int data_direction, -int task_attr, -unsigned char *sense_buffer,u64 unpacked_lun) +void __target_init_cmd (struct se_cmd *cmd, +const struct target_core_fabric_ops *tfo, +struct se_session *se_sess,u32 data_length, +int data_direction,int task_attr, +unsigned char *sense_buffer,u64 unpacked_lun, +struct target_cmd_counter *cmd_cnt) {INIT_LIST_HEAD (&cmd->se_delayed_node);INIT_LIST_HEAD (&cmd->se_qf_node);
@@ -1468,6 +1466,7 @@ void __target_init_cmd( cmd->sam_task_attr = task_attr; cmd->sense_buffer = sense_buffer; cmd->orig_fe_lun = unpacked_lun; + cmd->cmd_cnt = cmd_cnt;if (!(cmd->se_cmd_flags &SCF_USE_CPUID )) cmd->cpuid =raw_smp_processor_id ();
@@ -1687,7 +1686,8 @@ int target_init_cmd(struct se_cmd *se_cmd, struct se_session *se_sess,* target_core_fabric_ops->queue_status() callback */ __target_init_cmd (se_cmd, se_tpg->se_tpg_tfo, se_sess, data_length, - data_dir, task_attr, sense, unpacked_lun); + data_dir, task_attr, sense, unpacked_lun, + se_sess->cmd_cnt);/* * Obtain struct se_cmd->cmd_kref reference. A second kref_get here is
@@ -1982,7 +1982,8 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,BUG_ON (!se_tpg);__target_init_cmd (se_cmd, se_tpg->se_tpg_tfo, se_sess, -0 ,DMA_NONE ,TCM_SIMPLE_TAG , sense, unpacked_lun); +0 ,DMA_NONE ,TCM_SIMPLE_TAG , sense, unpacked_lun, + se_sess->cmd_cnt);/* * FIXME: Currently expect caller to handle se_cmd->se_tmr_req * allocation failure.
@@ -2986,7 +2987,6 @@ EXPORT_SYMBOL(transport_generic_free_cmd);*/ int target_get_sess_cmd (struct se_cmd *se_cmd,bool ack_kref) { -struct se_session *se_sess = se_cmd->se_sess;int ret =0 ;/*
@@ -3003,11 +3003,9 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref)* Users like xcopy do not use counters since they never do a stop * and wait. */ -if (se_sess->cmd_cnt) { -if (!percpu_ref_tryget_live (&se_sess->cmd_cnt->refcnt)) +if (se_cmd->cmd_cnt) { +if (!percpu_ref_tryget_live (&se_cmd->cmd_cnt->refcnt)) ret = -ESHUTDOWN ; -else - se_cmd->cmd_cnt = se_sess->cmd_cnt; }if (ret && ack_kref)target_put_sess_cmd (se_cmd);
drivers/target/target_core_xcopy.c +4 -4
@@ -591,8 +591,8 @@ static int target_xcopy_read_source( (unsigned long long)src_lba, transfer_length_block, src_bytes);__target_init_cmd (se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, src_bytes, -DMA_FROM_DEVICE ,0 , &xpt_cmd.sense_buffer[0 ],0 ); - +DMA_FROM_DEVICE ,0 , &xpt_cmd.sense_buffer[0 ],0 , +NULL ); rc =target_xcopy_setup_pt_cmd (&xpt_cmd, xop, src_dev, &cdb[0 ], remote_port);if (rc <0 ) {
@@ -636,8 +636,8 @@ static int target_xcopy_write_destination( (unsigned long long)dst_lba, transfer_length_block, dst_bytes);__target_init_cmd (se_cmd, &xcopy_pt_tfo, &xcopy_pt_sess, dst_bytes, -DMA_TO_DEVICE ,0 , &xpt_cmd.sense_buffer[0 ],0 ); - +DMA_TO_DEVICE ,0 , &xpt_cmd.sense_buffer[0 ],0 , +NULL ); rc =target_xcopy_setup_pt_cmd (&xpt_cmd, xop, dst_dev, &cdb[0 ], remote_port);if (rc <0 ) {
drivers/usb/gadget/function/f_tcm.c +2 -2
@@ -1054,7 +1054,7 @@ static void usbg_cmd_work(struct work_struct *work) tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, tv_nexus->tvn_se_sess, cmd->data_len,DMA_NONE , cmd->prio_attr, cmd->sense_iu.sense, - cmd->unpacked_lun); + cmd->unpacked_lun, NULL); goto out; }
@@ -1183,7 +1183,7 @@ static void bot_cmd_work(struct work_struct *work) tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, tv_nexus->tvn_se_sess, cmd->data_len,DMA_NONE , cmd->prio_attr, cmd->sense_iu.sense, - cmd->unpacked_lun); + cmd->unpacked_lun, NULL); goto out; }
include/target/target_core_fabric.h +5 -3
@@ -151,9 +151,11 @@ void transport_deregister_session_configfs(struct se_session *);void transport_deregister_session (struct se_session *); -void __target_init_cmd (struct se_cmd *, -const struct target_core_fabric_ops *, -struct se_session *,u32 ,int ,int ,unsigned char *,u64 ); +void __target_init_cmd (struct se_cmd *cmd, +const struct target_core_fabric_ops *tfo, +struct se_session *sess,u32 data_length,int data_direction, +int task_attr,unsigned char *sense_buffer,u64 unpacked_lun, +struct target_cmd_counter *cmd_cnt);int target_init_cmd (struct se_cmd *se_cmd,struct se_session *se_sess,unsigned char *sense,u64 unpacked_lun,u32 data_length,int task_attr,int data_dir,int flags);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 364/694 scsi: target: iscsit: isert: Alloc per conn cmd counter
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit 6d256bee602b131bd4fbc92863b6a1210bcf6325 ]
This has iscsit allocate a per conn cmd counter and converts iscsit/isert to use it instead of the per session one.
Stable-dep-of: 395cee83d02d ("scsi: target: iscsit: Stop/wait on cmds during conn close")
--- drivers/infiniband/ulp/isert/ib_isert.c | 4 ++-- drivers/target/iscsi/iscsi_target.c | 4 ++-- drivers/target/iscsi/iscsi_target_login.c | 17 +++++++---------- drivers/target/target_core_transport.c | 9 ++++++--- include/target/target_core_fabric.h | 3 +++ 5 files changed, 20 insertions(+), 17 deletions(-)
drivers/infiniband/ulp/isert/ib_isert.c +2 -2
@@ -2506,8 +2506,8 @@ isert_wait4cmds(struct iscsit_conn *conn)isert_info ("iscsit_conn %p\n" , conn);if (conn->sess) { -target_stop_session (conn->sess->se_sess); -target_wait_for_sess_cmds (conn->sess->se_sess); +target_stop_cmd_counter (conn->cmd_cnt); +target_wait_for_cmds (conn->cmd_cnt); } }
drivers/target/iscsi/iscsi_target.c +2 -2
@@ -1193,7 +1193,7 @@ int iscsit_setup_scsi_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, conn->sess->se_sess,be32_to_cpu (hdr->data_length), cmd->data_direction, sam_task_attr, cmd->sense_buffer +2 ,scsilun_to_int (&hdr->lun), - conn->sess->se_sess->cmd_cnt); + conn->cmd_cnt); pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -2057,7 +2057,7 @@ iscsit_handle_task_mgt_cmd(struct iscsit_conn *conn, struct iscsit_cmd *cmd, conn->sess->se_sess,0 ,DMA_NONE ,TCM_SIMPLE_TAG , cmd->sense_buffer +2 ,scsilun_to_int (&hdr->lun), - conn->sess->se_sess->cmd_cnt); + conn->cmd_cnt);target_get_sess_cmd (&cmd->se_cmd, true);
drivers/target/iscsi/iscsi_target_login.c +7 -10
@@ -324,18 +324,8 @@ static int iscsi_login_zero_tsih_s1( goto free_ops; } -/* -* This is temp for iser. It will be moved to per conn in later -* patches for iscsi. -*/ - sess->se_sess->cmd_cnt =target_alloc_cmd_counter (); -if (!sess->se_sess->cmd_cnt) - goto free_se_sess; -return 0 ; -free_se_sess: -transport_free_session (sess->se_sess); free_ops:kfree (sess->sess_ops); free_id:
@@ -1157,8 +1147,14 @@ static struct iscsit_conn *iscsit_alloc_conn(struct iscsi_np *np) goto free_conn_cpumask; } + conn->cmd_cnt =target_alloc_cmd_counter (); +if (!conn->cmd_cnt) + goto free_conn_allowed_cpumask; +return conn; +free_conn_allowed_cpumask: +free_cpumask_var (conn->allowed_cpumask); free_conn_cpumask:free_cpumask_var (conn->conn_cpumask); free_conn_ops:
@@ -1172,6 +1168,7 @@ static struct iscsit_conn *iscsit_alloc_conn(struct iscsi_np *np)void iscsit_free_conn (struct iscsit_conn *conn) { +target_free_cmd_counter (conn->cmd_cnt);free_cpumask_var (conn->allowed_cpumask);free_cpumask_var (conn->conn_cpumask);kfree (conn->conn_ops);
drivers/target/target_core_transport.c +6 -3
@@ -254,7 +254,7 @@ struct target_cmd_counter *target_alloc_cmd_counter(void) }EXPORT_SYMBOL_GPL (target_alloc_cmd_counter); -static void target_free_cmd_counter (struct target_cmd_counter *cmd_cnt) +void target_free_cmd_counter (struct target_cmd_counter *cmd_cnt) {/* * Drivers like loop do not call target_stop_session during session
@@ -265,6 +265,7 @@ static void target_free_cmd_counter(struct target_cmd_counter *cmd_cnt)percpu_ref_exit (&cmd_cnt->refcnt); } +EXPORT_SYMBOL_GPL (target_free_cmd_counter);/** * transport_init_session - initialize a session object
@@ -3170,13 +3171,14 @@ static void target_stop_cmd_counter_confirm(struct percpu_ref *ref)* target_stop_cmd_counter - Stop new IO from being added to the counter. * @cmd_cnt: counter to stop */ -static void target_stop_cmd_counter (struct target_cmd_counter *cmd_cnt) +void target_stop_cmd_counter (struct target_cmd_counter *cmd_cnt) {pr_debug ("Stopping command counter.\n" );if (!atomic_cmpxchg (&cmd_cnt->stopped,0 ,1 ))percpu_ref_kill_and_confirm (&cmd_cnt->refcnt, target_stop_cmd_counter_confirm); } +EXPORT_SYMBOL_GPL (target_stop_cmd_counter);/** * target_stop_session - Stop new IO from being queued on the session.
@@ -3192,7 +3194,7 @@ EXPORT_SYMBOL(target_stop_session);* target_wait_for_cmds - Wait for outstanding cmds. * @cmd_cnt: counter to wait for active I/O for. */ -static void target_wait_for_cmds (struct target_cmd_counter *cmd_cnt) +void target_wait_for_cmds (struct target_cmd_counter *cmd_cnt) {int ret;
@@ -3208,6 +3210,7 @@ static void target_wait_for_cmds(struct target_cmd_counter *cmd_cnt)wait_for_completion (&cmd_cnt->stop_done);pr_debug ("Waiting for cmds done.\n" ); } +EXPORT_SYMBOL_GPL (target_wait_for_cmds);/** * target_wait_for_sess_cmds - Wait for outstanding commands
include/target/target_core_fabric.h +3 -0
@@ -133,7 +133,10 @@ struct se_session *target_setup_session(struct se_portal_group *, struct se_session *, void *));void target_remove_session (struct se_session *); +void target_stop_cmd_counter (struct target_cmd_counter *cmd_cnt); +void target_wait_for_cmds (struct target_cmd_counter *cmd_cnt);struct target_cmd_counter *target_alloc_cmd_counter (void ); +void target_free_cmd_counter (struct target_cmd_counter *cmd_cnt);void transport_init_session (struct se_session *se_sess);struct se_session *transport_alloc_session (enum target_prot_op );
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 365/694 scsi: target: iscsit: Stop/wait on cmds during conn close
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit 395cee83d02de3073211b04fc85724f4abc663ad ]
This fixes a bug added in commit f36199355c64 ("scsi: target: iscsi: Fix cmd abort fabric stop race").
If we have multiple sessions to the same se_device we can hit a race where a LUN_RESET on one session cleans up the se_cmds from under another session which is being closed. This results in the closing session freeing its conn/session structs while they are still in use.
The bug is:
1. Session1 has IO se_cmd1.
2. Session2 can also have se_cmds for I/O and optionally TMRs for ABORTS but then gets a LUN_RESET.
3. The LUN_RESET on session2 sees the se_cmds on session1 and during the drain stages marks them all with CMD_T_ABORTED.
4. session1 is now closed so iscsit_release_commands_from_conn() only sees se_cmds with the CMD_T_ABORTED bit set and returns immediately even though we have outstanding commands.
5. session1's connection and session are freed.
6. The backend request for se_cmd1 completes and it accesses the freed connection/session.
This hooks the iscsit layer into the cmd counter code, so we can wait for all outstanding se_cmds before freeing the connection.
--- drivers/target/iscsi/iscsi_target.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/target/iscsi/iscsi_target.c +10 -0
@@ -4245,6 +4245,16 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn)iscsit_free_cmd (cmd, true); } + +/* +* Wait on commands that were cleaned up via the aborted_task path. +* LLDs that implement iscsit_wait_conn will already have waited for +* commands. +*/ +if (!conn->conn_transport->iscsit_wait_conn) { +target_stop_cmd_counter (conn->cmd_cnt); +target_wait_for_cmds (conn->cmd_cnt); + } } static void iscsit_stop_timers_for_cmds(
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 366/694 scsi: target: Fix multiple LUN_RESET handling
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit 673db054d7a2b5a470d7a25baf65956d005ad729 ]
This fixes a bug where an initiator thinks a LUN_RESET has cleaned up running commands when it hasn't. The bug was added in commit 51ec502a3266 ("target: Delete tmr from list before processing").
The problem occurs when:
1. We have N I/O cmds running in the target layer spread over 2 sessions.
2. The initiator sends a LUN_RESET for each session.
3. session1's LUN_RESET loops over all the running commands from both sessions and moves them to its local drain_task_list.
4. session2's LUN_RESET does not see the LUN_RESET from session1 because the commit above has it remove itself. session2 also does not see any commands since the other reset moved them off the state lists.
5. sessions2's LUN_RESET will then complete with a successful response.
6. sessions2's inititor believes the running commands on its session are now cleaned up due to the successful response and cleans up the running commands from its side. It then restarts them.
7. The commands do eventually complete on the backend and the target starts to return aborted task statuses for them. The initiator will either throw a invalid ITT error or might accidentally lookup a new task if the ITT has been reallocated already.
Fix the bug by reverting the patch, and serialize the execution of LUN_RESETs and Preempt and Aborts.
Also prevent us from waiting on LUN_RESETs in core_tmr_drain_tmr_list, because it turns out the original patch fixed a bug that was not mentioned. For LUN_RESET1 core_tmr_drain_tmr_list can see a second LUN_RESET and wait on it. Then the second reset will run core_tmr_drain_tmr_list and see the first reset and wait on it resulting in a deadlock.
--- drivers/target/target_core_device.c | 1 + drivers/target/target_core_tmr.c | 26 +++++++++++++++++++++++--- include/target/target_core_base.h | 1 + 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/target/target_core_device.c +1 -0
@@ -782,6 +782,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)spin_lock_init (&dev->t10_alua.lba_map_lock);INIT_WORK (&dev->delayed_cmd_work, target_do_delayed_work); +mutex_init (&dev->lun_reset_mutex); dev->t10_wwn.t10_dev = dev;/*
drivers/target/target_core_tmr.c +23 -3
@@ -188,14 +188,23 @@ static void core_tmr_drain_tmr_list(* LUN_RESET tmr.. */ spin_lock_irqsave (&dev->se_tmr_lock, flags); -if (tmr) -list_del_init (&tmr->tmr_list);list_for_each_entry_safe (tmr_p, tmr_pp, &dev->dev_tmr_list, tmr_list) { +if (tmr_p == tmr) +continue ; + cmd = tmr_p->task_cmd;if (!cmd) {pr_err ("Unable to locate struct se_cmd for TMR\n" );continue ; } + +/* +* We only execute one LUN_RESET at a time so we can't wait +* on them below. +*/ +if (tmr_p->function ==TMR_LUN_RESET ) +continue ; +/* * If this function was called with a valid pr_res_key * parameter (eg: for PROUT PREEMPT_AND_ABORT service action
@@ -379,14 +388,25 @@ int core_tmr_lun_reset( tmr_nacl->initiatorname); } } + + +/* +* We only allow one reset or preempt and abort to execute at a time +* to prevent one call from claiming all the cmds causing a second +* call from returning while cmds it should have waited on are still +* running. +*/ +mutex_lock (&dev->lun_reset_mutex); +pr_debug ("LUN_RESET: %s starting for [%s], tas: %d\n" , (preempt_and_abort_list) ?"Preempt" :"TMR" , dev->transport->name, tas); -core_tmr_drain_tmr_list (dev, tmr, preempt_and_abort_list);core_tmr_drain_state_list (dev, prout_cmd, tmr_sess, tas, preempt_and_abort_list); +mutex_unlock (&dev->lun_reset_mutex); +/* * Clear any legacy SPC-2 reservation when called during * LOGICAL UNIT RESET
include/target/target_core_base.h +1 -0
@@ -872,6 +872,7 @@ struct se_device {struct rcu_head rcu_head;int queue_cnt;struct se_device_queue *queues; +struct mutex lun_reset_mutex; };struct target_opcode_descriptor {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 367/694 scsi: target: iscsit: Fix TAS handling during conn cleanup
In reply to Greg Kroah-HartmanFrom: Mike Christie <[email protected]>
[ Upstream commit cc79da306ebb2edb700c3816b90219223182ac3c ]
Fix a bug added in commit f36199355c64 ("scsi: target: iscsi: Fix cmd abort fabric stop race").
If CMD_T_TAS is set on the se_cmd we must call iscsit_free_cmd() to do the last put on the cmd and free it, because the connection is down and we will not up sending the response and doing the put from the normal I/O path.
Add a check for CMD_T_TAS in iscsit_release_commands_from_conn() so we now detect this case and run iscsit_free_cmd().
--- drivers/target/iscsi/iscsi_target.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/target/iscsi/iscsi_target.c +9 -7
@@ -4220,9 +4220,12 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn)list_for_each_entry_safe (cmd, cmd_tmp, &tmp_list, i_conn_node) {struct se_cmd *se_cmd = &cmd->se_cmd; -if (se_cmd->se_tfo !=NULL ) { -spin_lock_irq (&se_cmd->t_state_lock); -if (se_cmd->transport_state &CMD_T_ABORTED ) { +if (!se_cmd->se_tfo) +continue ; + +spin_lock_irq (&se_cmd->t_state_lock); +if (se_cmd->transport_state &CMD_T_ABORTED ) { +if (!(se_cmd->transport_state &CMD_T_TAS ))/* * LIO's abort path owns the cleanup for this, * so put it back on the list and let
@@ -4230,11 +4233,10 @@ static void iscsit_release_commands_from_conn(struct iscsit_conn *conn)*/ list_move_tail (&cmd->i_conn_node, &conn->conn_cmd_list); - }else { - se_cmd->transport_state |=CMD_T_FABRIC_STOP ; - } -spin_unlock_irq (&se_cmd->t_state_lock); + }else { + se_cmd->transport_state |=CMD_T_FABRIC_STOP ; } +spin_unlock_irq (&se_cmd->t_state_lock); }spin_unlock_bh (&conn->cmd_lock);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 368/694 scsi: megaraid: Fix mega_cmd_done() CMDID_INT_CMDS
In reply to Greg Kroah-HartmanFrom: Danila Chernetsov <[email protected]>
[ Upstream commit 75cb113cd43f06aaf4f1bda0069cfd5b98e909eb ]
When cmdid == CMDID_INT_CMDS, the 'cmds' pointer is NULL but is dereferenced below.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/scsi/megaraid.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/megaraid.c +1 -0
@@ -1441,6 +1441,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)*/ if (cmdid ==CMDID_INT_CMDS ) { scb = &adapter->int_scb; + cmd = scb->cmd;list_del_init (&scb->list); scb->state =SCB_FREE ;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 369/694 net: sunhme: Fix uninitialized return code
In reply to Greg Kroah-HartmanFrom: Sean Anderson <[email protected]>
[ Upstream commit d61157414d0a591d10d27d0ce5873916614e5e31 ]
Fix an uninitialized return code if we never found a qfe slot. It would be a bug if we ever got into this situation, but it's good to return something tracable.
--- drivers/net/ethernet/sun/sunhme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/sun/sunhme.c +1 -1
@@ -2834,7 +2834,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,int i, qfe_slot =-1 ;char prom_name[64 ];u8 addr[ETH_ALEN ]; -int err; +int err = -ENODEV ;/* Now make sure pci_dev cookie is there. */ #ifdef CONFIG_SPARC
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 370/694 testing/vsock: add vsock_perf to gitignore
In reply to Greg Kroah-HartmanFrom: Bobby Eshleman <[email protected]>
[ Upstream commit 24265c2c91ad6aae9446e18472566cd83e92b602 ]
This adds the vsock_perf binary to the gitignore file.
--- tools/testing/vsock/.gitignore | 1 + 1 file changed, 1 insertion(+)
tools/testing/vsock/.gitignore +1 -0
@@ -2,3 +2,4 @@ *.d vsock_test vsock_diag_test +vsock_perf
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 371/694 f2fs: handle dqget error in f2fs_transfer_project_quota()
In reply to Greg Kroah-HartmanFrom: Yangtao Li <[email protected]>
[ Upstream commit 8051692f5f23260215bfe9a72e712d93606acc5f ]
We should set the error code when dqget() failed.
--- fs/f2fs/file.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
fs/f2fs/file.c +8 -7
@@ -3009,15 +3009,16 @@ int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid)struct dquot *transfer_to[MAXQUOTAS ] = {};struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct super_block *sb = sbi->sb; -int err =0 ; +int err; transfer_to[PRJQUOTA ] =dqget (sb,make_kqid_projid (kprojid)); -if (!IS_ERR (transfer_to[PRJQUOTA ])) { - err =__dquot_transfer (inode, transfer_to); -if (err) -set_sbi_flag (sbi,SBI_QUOTA_NEED_REPAIR ); -dqput (transfer_to[PRJQUOTA ]); - } +if (IS_ERR (transfer_to[PRJQUOTA ])) +return PTR_ERR (transfer_to[PRJQUOTA ]); + + err =__dquot_transfer (inode, transfer_to); +if (err) +set_sbi_flag (sbi,SBI_QUOTA_NEED_REPAIR ); +dqput (transfer_to[PRJQUOTA ]);return err; }
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 372/694 f2fs: fix uninitialized skipped_gc_rwsem
In reply to Greg Kroah-HartmanFrom: Yonggil Song <[email protected]>
[ Upstream commit c17caf0ba3aa3411b96c71b4ce24be1040b8f3e8 ]
When f2fs skipped a gc round during victim migration, there was a bug which would skip all upcoming gc rounds unconditionally because skipped_gc_rwsem was not initialized. It fixes the bug by correctly initializing the skipped_gc_rwsem inside the gc loop.
--- fs/f2fs/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/f2fs/gc.c +1 -1
@@ -1791,8 +1791,8 @@ int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) prefree_segments(sbi)); cpc.reason =__get_cp_reason (sbi); - sbi->skipped_gc_rwsem =0 ; gc_more: + sbi->skipped_gc_rwsem =0 ;if (unlikely (!(sbi->sb->s_flags &SB_ACTIVE ))) { ret = -EINVAL ; goto stop;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 373/694 f2fs: apply zone capacity to all zone type
In reply to Greg Kroah-HartmanFrom: Jaegeuk Kim <[email protected]>
[ Upstream commit 0b37ed21e3367539b79284e0b0af2246ffcf0dca ]
If we manage the zone capacity per zone type, it'll break the GC assumption. And, the current logic complains valid block count mismatch. Let's apply zone capacity to all zone type, if specified.
--- fs/f2fs/segment.c | 65 +++-------------------------------------------- fs/f2fs/segment.h | 3 +++ 2 files changed, 7 insertions(+), 61 deletions(-)
fs/f2fs/segment.c +4 -61
@@ -4920,48 +4920,6 @@ int f2fs_check_write_pointer(struct f2fs_sb_info *sbi)return 0 ; } -static bool is_conv_zone (struct f2fs_sb_info *sbi,unsigned int zone_idx, -unsigned int dev_idx) -{ -if (!bdev_is_zoned (FDEV (dev_idx).bdev)) -return true; -return !test_bit (zone_idx,FDEV (dev_idx).blkz_seq); -} - -/* Return the zone index in the given device */ -static unsigned int get_zone_idx (struct f2fs_sb_info *sbi,unsigned int secno, -int dev_idx) -{ -block_t sec_start_blkaddr =START_BLOCK (sbi,GET_SEG_FROM_SEC (sbi, secno)); - -return (sec_start_blkaddr -FDEV (dev_idx).start_blk) >> - sbi->log_blocks_per_blkz; -} - -/* -* Return the usable segments in a section based on the zone's -* corresponding zone capacity. Zone is equal to a section. -*/ -static inline unsigned int f2fs_usable_zone_segs_in_sec ( -struct f2fs_sb_info *sbi,unsigned int segno) -{ -unsigned int dev_idx, zone_idx; - - dev_idx =f2fs_target_device_index (sbi,START_BLOCK (sbi, segno)); - zone_idx =get_zone_idx (sbi,GET_SEC_FROM_SEG (sbi, segno), dev_idx); - -/* Conventional zone's capacity is always equal to zone size */ -if (is_conv_zone (sbi, zone_idx, dev_idx)) -return sbi->segs_per_sec; - -if (!sbi->unusable_blocks_per_sec) -return sbi->segs_per_sec; - -/* Get the segment count beyond zone capacity block */ -return sbi->segs_per_sec - (sbi->unusable_blocks_per_sec >> - sbi->log_blocks_per_seg); -} -/* * Return the number of usable blocks in a segment. The number of blocks * returned is always equal to the number of blocks in a segment for
@@ -4974,23 +4932,13 @@ static inline unsigned int f2fs_usable_zone_blks_in_seg( struct f2fs_sb_info *sbi, unsigned int segno) {block_t seg_start, sec_start_blkaddr, sec_cap_blkaddr; -unsigned int zone_idx, dev_idx, secno; - - secno =GET_SEC_FROM_SEG (sbi, segno); - seg_start =START_BLOCK (sbi, segno); - dev_idx =f2fs_target_device_index (sbi, seg_start); - zone_idx =get_zone_idx (sbi, secno, dev_idx); - -/* -* Conventional zone's capacity is always equal to zone size, -* so, blocks per segment is unchanged. -*/ -if (is_conv_zone (sbi, zone_idx, dev_idx)) -return sbi->blocks_per_seg; +unsigned int secno;if (!sbi->unusable_blocks_per_sec)return sbi->blocks_per_seg; + secno =GET_SEC_FROM_SEG (sbi, segno); + seg_start =START_BLOCK (sbi, segno); sec_start_blkaddr =START_BLOCK (sbi,GET_SEG_FROM_SEC (sbi, secno)); sec_cap_blkaddr = sec_start_blkaddr +CAP_BLKS_PER_SEC (sbi);
@@ -5024,11 +4972,6 @@ static inline unsigned int f2fs_usable_zone_blks_in_seg(struct f2fs_sb_info *sbi return 0; } -static inline unsigned int f2fs_usable_zone_segs_in_sec (struct f2fs_sb_info *sbi, -unsigned int segno) -{ -return 0 ; -}#endif unsigned int f2fs_usable_blks_in_seg (struct f2fs_sb_info *sbi,unsigned int segno)
@@ -5043,7 +4986,7 @@ unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, unsigned int segno) {if (f2fs_sb_has_blkzoned (sbi)) -return f2fs_usable_zone_segs_in_sec (sbi, segno); +return CAP_SEGS_PER_SEC (sbi);return sbi->segs_per_sec; }
fs/f2fs/segment.h +3 -0
@@ -104,6 +104,9 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi,#define CAP_BLKS_PER_SEC (sbi) \ ((sbi)->segs_per_sec * (sbi)->blocks_per_seg - \ (sbi)->unusable_blocks_per_sec) +#define CAP_SEGS_PER_SEC (sbi) \ + ((sbi)->segs_per_sec - ((sbi)->unusable_blocks_per_sec >>\ + (sbi)->log_blocks_per_seg))#define GET_SEC_FROM_SEG (sbi, segno) \ (((segno) == -1) ? -1: (segno) / (sbi)->segs_per_sec)#define GET_SEG_FROM_SEC (sbi, secno) \
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 374/694 f2fs: compress: fix to call f2fs_wait_on_page_writeback() in f2fs_write_raw_pages()
In reply to Greg Kroah-HartmanFrom: Yangtao Li <[email protected]>
[ Upstream commit babedcbac164cec970872b8097401ca913a80e61 ]
BUG_ON() will be triggered when writing files concurrently, because the same page is writtenback multiple times.
1597 void folio_end_writeback(struct folio *folio)
1598 {
......
1618 if (!__folio_end_writeback(folio))
1619 BUG();
......1625 }
kernel BUG at mm/filemap.c:1619!
Call Trace: <TASK> f2fs_write_end_io+0x1a0/0x370 blk_update_request+0x6c/0x410 blk_mq_end_request+0x15/0x130 blk_complete_reqs+0x3c/0x50 __do_softirq+0xb8/0x29b ? sort_range+0x20/0x20 run_ksoftirqd+0x19/0x20 smpboot_thread_fn+0x10b/0x1d0 kthread+0xde/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x22/0x30 </TASK>
Below is the concurrency scenario:
[Process A] [Process B] [Process C]f2fs_write_raw_pages()
- redirty_page_for_writepage()
- unlock page()
f2fs_do_write_data_page()
- lock_page()
- clear_page_dirty_for_io()
- set_page_writeback() [1st writeback]
.....
- unlock page()
generic_perform_write()
- f2fs_write_begin()
- wait_for_stable_page()
- f2fs_write_end()
- set_page_dirty()
- lock_page()
- f2fs_do_write_data_page()
- set_page_writeback() [2st writeback]
This problem was introduced by the previous commit 7377e853967b ("f2fs:
compress: fix potential deadlock of compress file"). All pagelocks were released in f2fs_write_raw_pages(), but whether the page was in the writeback state was ignored in the subsequent writing process. Let's fix it by waiting for the page to writeback before writing.
--- fs/f2fs/compress.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/f2fs/compress.c +6 -0
@@ -1456,6 +1456,12 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,if (!PageDirty (cc->rpages[i])) goto continue_unlock; +if (PageWriteback (cc->rpages[i])) { +if (wbc->sync_mode ==WB_SYNC_NONE ) + goto continue_unlock; +f2fs_wait_on_page_writeback (cc->rpages[i],DATA , true, true); + } +if (!clear_page_dirty_for_io (cc->rpages[i])) goto continue_unlock;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 375/694 f2fs: fix scheduling while atomic in decompression path
In reply to Greg Kroah-HartmanFrom: Jaegeuk Kim <[email protected]>
[ Upstream commit 1aa161e43106d46ca8e9a86f4aa28d420258134b ]
[ 16.945668][ C0] Call trace: [ 16.945678][ C0] dump_backtrace+0x110/0x204 [ 16.945706][ C0] dump_stack_lvl+0x84/0xbc [ 16.945735][ C0] __schedule_bug+0xb8/0x1ac [ 16.945756][ C0] __schedule+0x724/0xbdc [ 16.945778][ C0] schedule+0x154/0x258 [ 16.945793][ C0] bit_wait_io+0x48/0xa4 [ 16.945808][ C0] out_of_line_wait_on_bit+0x114/0x198 [ 16.945824][ C0] __sync_dirty_buffer+0x1f8/0x2e8 [ 16.945853][ C0] __f2fs_commit_super+0x140/0x1f4 [ 16.945881][ C0] f2fs_commit_super+0x110/0x28c [ 16.945898][ C0] f2fs_handle_error+0x1f4/0x2f4 [ 16.945917][ C0] f2fs_decompress_cluster+0xc4/0x450 [ 16.945942][ C0] f2fs_end_read_compressed_page+0xc0/0xfc [ 16.945959][ C0] f2fs_handle_step_decompress+0x118/0x1cc [ 16.945978][ C0] f2fs_read_end_io+0x168/0x2b0 [ 16.945993][ C0] bio_endio+0x25c/0x2c8 [ 16.946015][ C0] dm_io_dec_pending+0x3e8/0x57c [ 16.946052][ C0] clone_endio+0x134/0x254 [ 16.946069][ C0] bio_endio+0x25c/0x2c8 [ 16.946084][ C0] blk_update_request+0x1d4/0x478 [ 16.946103][ C0] scsi_end_request+0x38/0x4cc [ 16.946129][ C0] scsi_io_completion+0x94/0x184 [ 16.946147][ C0] scsi_finish_command+0xe8/0x154 [ 16.946164][ C0] scsi_complete+0x90/0x1d8 [ 16.946181][ C0] blk_done_softirq+0xa4/0x11c [ 16.946198][ C0] _stext+0x184/0x614 [ 16.946214][ C0] __irq_exit_rcu+0x78/0x144 [ 16.946234][ C0] handle_domain_irq+0xd4/0x154 [ 16.946260][ C0] gic_handle_irq.33881+0x5c/0x27c [ 16.946281][ C0] call_on_irq_stack+0x40/0x70 [ 16.946298][ C0] do_interrupt_handler+0x48/0xa4 [ 16.946313][ C0] el1_interrupt+0x38/0x68 [ 16.946346][ C0] el1h_64_irq_handler+0x20/0x30 [ 16.946362][ C0] el1h_64_irq+0x78/0x7c [ 16.946377][ C0] finish_task_switch+0xc8/0x3d8 [ 16.946394][ C0] __schedule+0x600/0xbdc [ 16.946408][ C0] preempt_schedule_common+0x34/0x5c [ 16.946423][ C0] preempt_schedule+0x44/0x48 [ 16.946438][ C0] process_one_work+0x30c/0x550 [ 16.946456][ C0] worker_thread+0x414/0x8bc [ 16.946472][ C0] kthread+0x16c/0x1e0 [ 16.946486][ C0] ret_from_fork+0x10/0x20
--- fs/f2fs/compress.c | 7 ++++++- fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/compress.c +6 -1
@@ -755,7 +755,12 @@ void f2fs_decompress_cluster(struct decompress_io_ctx *dic, bool in_task)if (dic->clen >PAGE_SIZE * dic->nr_cpages -COMPRESS_HEADER_SIZE ) { ret = -EFSCORRUPTED ; -f2fs_handle_error (sbi,ERROR_FAIL_DECOMPRESSION ); + +/* Avoid f2fs_commit_super in irq context */ +if (in_task) +f2fs_save_errors (sbi,ERROR_FAIL_DECOMPRESSION ); +else +f2fs_handle_error (sbi,ERROR_FAIL_DECOMPRESSION ); goto out_release; }
fs/f2fs/f2fs.h +1 -0
@@ -3554,6 +3554,7 @@ int f2fs_quota_sync(struct super_block *sb, int type);loff_t max_file_blocks (struct inode *inode);void f2fs_quota_off_umount (struct super_block *sb);void f2fs_handle_stop (struct f2fs_sb_info *sbi,unsigned char reason); +void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag);void f2fs_handle_error (struct f2fs_sb_info *sbi,unsigned char error);int f2fs_commit_super (struct f2fs_sb_info *sbi,bool recover);int f2fs_sync_fs (struct super_block *sb,int sync);
fs/f2fs/super.c +1 -1
@@ -3885,7 +3885,7 @@ void f2fs_handle_stop(struct f2fs_sb_info *sbi, unsigned char reason)f2fs_up_write (&sbi->sb_lock); } -static void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag) +void f2fs_save_errors (struct f2fs_sb_info *sbi,unsigned char flag) {spin_lock (&sbi->error_lock);if (!test_bit (flag, (unsigned long *)sbi->errors)) {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 376/694 crypto: caam - Clear some memory in instantiate_rng
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit 9c19fb86a8cb2ee82a832c95e139f29ea05c4d08 ]
According to the comment at the end of the 'for' loop just a few lines below, it looks needed to clear 'desc'.
So it should also be cleared for the first iteration.
Move the memset() to the beginning of the loop to be safe.
--- drivers/crypto/caam/ctrl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/crypto/caam/ctrl.c +4 -2
@@ -284,6 +284,10 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,const u32 rdsta_if =RDSTA_IF0 << sh_idx;const u32 rdsta_pr =RDSTA_PR0 << sh_idx;const u32 rdsta_mask = rdsta_if | rdsta_pr; + +/* Clear the contents before using the descriptor */ +memset (desc,0x00 ,CAAM_CMD_SZ *7 ); +/* * If the corresponding bit is set, this state handle * was initialized by somebody else, so it's left alone.
@@ -327,8 +331,6 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask, }dev_info (ctrldev,"Instantiated RNG4 SH%d\n" , sh_idx); -/* Clear the contents before recreating the descriptor */ -memset (desc,0x00 ,CAAM_CMD_SZ *7 ); }kfree (desc);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 377/694 crypto: sa2ul - Select CRYPTO_DES
In reply to Greg Kroah-HartmanFrom: Suman Anna <[email protected]>
[ Upstream commit 8832023efd20966e29944dac92118dfbf1fa1bc0 ]
The SA2UL Crypto driver provides support for couple of
DES3 algos "cbc(des3_ede)" and "ecb(des3_ede)", and enabling the crypto selftest throws the following errors (as seen on
K3 J721E SoCs):
saul-crypto 4e00000.crypto: Error allocating fallback algo cbc(des3_ede)
alg: skcipher: failed to allocate transform for cbc-des3-sa2ul: -2 saul-crypto 4e00000.crypto: Error allocating fallback algo ecb(des3_ede)
alg: skcipher: failed to allocate transform for ecb-des3-sa2ul: -2
Fix this by selecting CRYPTO_DES which was missed while adding base driver support.
--- drivers/crypto/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/Kconfig +1 -0
@@ -810,6 +810,7 @@ config CRYPTO_DEV_SA2UL select CRYPTO_AES select CRYPTO_ALGAPI select CRYPTO_AUTHENC + select CRYPTO_DES select CRYPTO_SHA1 select CRYPTO_SHA256 select CRYPTO_SHA512
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 378/694 wifi: rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_rfreg()
In reply to Greg Kroah-HartmanFrom: Wei Chen <[email protected]>
[ Upstream commit 905a9241e4e8c15d2c084fee916280514848fe35 ]
If there is a failure during copy_from_user or user-provided data buffer is invalid, rtl_debugfs_set_write_rfreg should return negative error code instead of a positive value count.
Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by copy_from_user.
--- drivers/net/wireless/realtek/rtlwifi/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtlwifi/debug.c +3 -3
@@ -375,8 +375,8 @@ static ssize_t rtl_debugfs_set_write_rfreg(struct file *filp, tmp_len = (count >sizeof (tmp) -1 ?sizeof (tmp) -1 : count); -if (!buffer ||copy_from_user (tmp, buffer, tmp_len)) -return count; +if (copy_from_user (tmp, buffer, tmp_len)) +return -EFAULT ; tmp[tmp_len] ='\0' ;
@@ -386,7 +386,7 @@ static ssize_t rtl_debugfs_set_write_rfreg(struct file *filp,if (num !=4 ) {rtl_dbg (rtlpriv,COMP_ERR ,DBG_DMESG ,"Format is <path> <addr> <mask> <data>\n" ); -return count; +return -EINVAL ; }rtl_set_rfreg (hw, path, addr, bitmask, data);
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 379/694 wifi: rtlwifi: fix incorrect error codes in rtl_debugfs_set_write_reg()
In reply to Greg Kroah-HartmanFrom: Wei Chen <[email protected]>
[ Upstream commit 5dbe1f8eb8c5ac69394400a5b86fd81775e96c43 ]
If there is a failure during copy_from_user or user-provided data buffer is invalid, rtl_debugfs_set_write_reg should return negative error code instead of a positive value count.
Fix this bug by returning correct error code. Moreover, the check of buffer against null is removed since it will be handled by copy_from_user.
--- drivers/net/wireless/realtek/rtlwifi/debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtlwifi/debug.c +3 -3
@@ -278,8 +278,8 @@ static ssize_t rtl_debugfs_set_write_reg(struct file *filp, tmp_len = (count >sizeof (tmp) -1 ?sizeof (tmp) -1 : count); -if (!buffer ||copy_from_user (tmp, buffer, tmp_len)) -return count; +if (copy_from_user (tmp, buffer, tmp_len)) +return -EFAULT ; tmp[tmp_len] ='\0' ;
@@ -287,7 +287,7 @@ static ssize_t rtl_debugfs_set_write_reg(struct file *filp, num =sscanf (tmp,"%x %x %x" , &addr, &val, &len);if (num !=3 ) -return count; +return -EINVAL ;switch (len) {case 1 :
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 380/694 scsi: hisi_sas: Handle NCQ error when IPTT is valid
In reply to Greg Kroah-HartmanFrom: Xingui Yang <[email protected]>
[ Upstream commit bb544224da77b96b2c11a13872bf91ede1e015be ]
If an NCQ error occurs when the IPTT is valid and slot->abort flag is set in completion path, sas_task_abort() will be called to abort only one NCQ command now, and the host would be set to SHOST_RECOVERY state. But this may not kick-off EH Immediately until other outstanding QCs timeouts. As a result, the host may remain in the SHOST_RECOVERY state for up to 30 seconds, such as follows:
[7972317.645234] hisi_sas_v3_hw 0000:74:04.0: erroneous completion iptt=3264 task=00000000466116b8 dev id=2 sas_addr=0x5000000000000502 CQ hdr: 0x1883 0x20cc0 0x40000 0x20420000 Error info: 0x0 0x0 0x200000 0x0 [7972341.508264] sas: Enter sas_scsi_recover_host busy: 32 failed: 32 [7972341.984731] sas: --- Exit sas_scsi_recover_host: busy: 0 failed: 32 tries: 1
All NCQ commands that are in the queue should be aborted when an NCQ error occurs in this scenario.
--- drivers/scsi/hisi_sas/hisi_sas_v1_hw.c | 6 +++++- drivers/scsi/hisi_sas/hisi_sas_v2_hw.c | 6 +++++- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v1_hw.c +5 -1
@@ -1258,7 +1258,11 @@ static void slot_complete_v1_hw(struct hisi_hba *hisi_hba,slot_err_v1_hw (hisi_hba, task, slot);if (unlikely (slot->abort)) { -sas_task_abort (task); +if (dev_is_sata (device) && task->ata_task.use_ncq) +sas_ata_device_link_abort (device, true); +else +sas_task_abort (task); +return ; } goto out;
drivers/scsi/hisi_sas/hisi_sas_v2_hw.c +5 -1
@@ -2404,7 +2404,11 @@ static void slot_complete_v2_hw(struct hisi_hba *hisi_hba, error_info[2], error_info[3]);if (unlikely (slot->abort)) { -sas_task_abort (task); +if (dev_is_sata (device) && task->ata_task.use_ncq) +sas_ata_device_link_abort (device, true); +else +sas_task_abort (task); +return ; } goto out;
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +5 -1
@@ -2320,7 +2320,11 @@ static void slot_complete_v3_hw(struct hisi_hba *hisi_hba, error_info[0 ], error_info[1 ], error_info[2], error_info[3]);if (unlikely (slot->abort)) { -sas_task_abort (task); +if (dev_is_sata (device) && task->ata_task.use_ncq) +sas_ata_device_link_abort (device, true); +else +sas_task_abort (task); +return ; } goto out;
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 381/694 wifi: rt2x00: Fix memory leak when handling surveys
In reply to Greg Kroah-HartmanFrom: Armin Wolf <[email protected]>
[ Upstream commit cbef9a83c51dfcb07f77cfa6ac26f53a1ea86f49 ]
When removing a rt2x00 device, its associated channel surveys are not freed, causing a memory leak observable with kmemleak:
unreferenced object 0xffff9620f0881a00 (size 512):
comm "systemd-udevd", pid 2290, jiffies 4294906974 (age 33.768s) hex dump (first 32 bytes):
70 44 12 00 00 00 00 00 92 8a 00 00 00 00 00 00 pD..............
00 00 00 00 00 00 00 00 ab 87 01 00 00 00 00 00 ................
backtrace:
[<ffffffffb0ed858b>] __kmalloc+0x4b/0x130
[<ffffffffc1b0f29b>] rt2800_probe_hw+0xc2b/0x1380 [rt2800lib]
[<ffffffffc1a9496e>] rt2800usb_probe_hw+0xe/0x60 [rt2800usb]
[<ffffffffc1ae491a>] rt2x00lib_probe_dev+0x21a/0x7d0 [rt2x00lib]
[<ffffffffc1b3b83e>] rt2x00usb_probe+0x1be/0x980 [rt2x00usb]
[<ffffffffc05981e2>] usb_probe_interface+0xe2/0x310 [usbcore]
[<ffffffffb13be2d5>] really_probe+0x1a5/0x410
[<ffffffffb13be5c8>] __driver_probe_device+0x78/0x180
[<ffffffffb13be6fe>] driver_probe_device+0x1e/0x90
[<ffffffffb13be972>] __driver_attach+0xd2/0x1c0
[<ffffffffb13bbc57>] bus_for_each_dev+0x77/0xd0
[<ffffffffb13bd2a2>] bus_add_driver+0x112/0x210
[<ffffffffb13bfc6c>] driver_register+0x5c/0x120
[<ffffffffc0596ae8>] usb_register_driver+0x88/0x150 [usbcore]
[<ffffffffb0c011c4>] do_one_initcall+0x44/0x220
[<ffffffffb0d6134c>] do_init_module+0x4c/0x220Fix this by freeing the channel surveys on device removal.
Tested with a RT3070 based USB wireless adapter.
--- drivers/net/wireless/ralink/rt2x00/rt2x00dev.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c +1 -0
@@ -1091,6 +1091,7 @@ static void rt2x00lib_remove_hw(struct rt2x00_dev *rt2x00dev) }kfree (rt2x00dev->spec.channels_info); +kfree (rt2x00dev->chan_survey); }static const struct ieee80211_tpt_blink rt2x00_tpt_blink[] = {
Signature · 1 line
2.39.2
Greg Kroah-Hartman
maintainerPATCH 382/694 bpf: factor out fetching basic kfunc metadata
In reply to Greg Kroah-HartmanFrom: Andrii Nakryiko <[email protected]>
[ Upstream commit 07236eab7a3139da97aef9f5f21f403be82a82ea ]
Factor out logic to fetch basic kfunc metadata based on struct bpf_insn. This is not exactly short or trivial code to just copy/paste and this information is sometimes necessary in other parts of the verifier logic. Subsequent patches will rely on this to determine if an instruction is a kfunc call to iterator next method.
No functional changes intended, including that verbose() warning behavior when kfunc is not allowed for a particular program type.
Stable-dep-of: f6a6a5a97628 ("bpf: Fix struct_meta lookup for bpf_obj_free_fields kfunc call")
--- kernel/bpf/verifier.c | 92 +++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 33 deletions(-)
kernel/bpf/verifier.c +59 -33
@@ -9788,24 +9788,21 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_return 0 ; } -static int check_kfunc_call (struct bpf_verifier_env *env,struct bpf_insn *insn, -int *insn_idx_p) +static int fetch_kfunc_meta (struct bpf_verifier_env *env, +struct bpf_insn *insn, +struct bpf_kfunc_call_arg_meta *meta, +const char **kfunc_name) { -const struct btf_type *t, *func, *func_proto, *ptr_type; -u32 i, nargs, func_id, ptr_type_id, release_ref_obj_id; -struct bpf_reg_state *regs =cur_regs (env); -const char *func_name, *ptr_type_name; -bool sleepable, rcu_lock, rcu_unlock; -struct bpf_kfunc_call_arg_meta meta; -int err, insn_idx = *insn_idx_p; -const struct btf_param *args; -const struct btf_type *ret_t; +const struct btf_type *func, *func_proto; +u32 func_id, *kfunc_flags; +const char *func_name;struct btf *desc_btf; -u32 *kfunc_flags; -/* skip for now, but return error when we find this in fixup_kfunc_call */ +if (kfunc_name) + *kfunc_name =NULL ; +if (!insn->imm) -return 0 ; +return -EINVAL ; desc_btf =find_kfunc_desc_btf (env, insn->off);if (IS_ERR (desc_btf))
@@ -9814,22 +9811,51 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, func_id = insn->imm; func =btf_type_by_id (desc_btf, func_id); func_name =btf_name_by_offset (desc_btf, func->name_off); +if (kfunc_name) + *kfunc_name = func_name; func_proto =btf_type_by_id (desc_btf, func->type); kfunc_flags =btf_kfunc_id_set_contains (desc_btf,resolve_prog_type (env->prog), func_id);if (!kfunc_flags) { -verbose (env,"calling kernel function %s is not allowed\n" , - func_name);return -EACCES ; } -/* Prepare kfunc call metadata */ -memset (&meta,0 ,sizeof (meta)); - meta.btf = desc_btf; - meta.func_id = func_id; - meta.kfunc_flags = *kfunc_flags; - meta.func_proto = func_proto; - meta.func_name = func_name; +memset (meta,0 ,sizeof (*meta)); + meta->btf = desc_btf; + meta->func_id = func_id; + meta->kfunc_flags = *kfunc_flags; + meta->func_proto = func_proto; + meta->func_name = func_name; + +return 0 ; +} + +static int check_kfunc_call (struct bpf_verifier_env *env,struct bpf_insn *insn, +int *insn_idx_p) +{ +const struct btf_type *t, *ptr_type; +u32 i, nargs, ptr_type_id, release_ref_obj_id; +struct bpf_reg_state *regs =cur_regs (env); +const char *func_name, *ptr_type_name; +bool sleepable, rcu_lock, rcu_unlock; +struct bpf_kfunc_call_arg_meta meta; +struct bpf_insn_aux_data *insn_aux; +int err, insn_idx = *insn_idx_p; +const struct btf_param *args; +const struct btf_type *ret_t; +struct btf *desc_btf; + +/* skip for now, but return error when we find this in fixup_kfunc_call */ +if (!insn->imm) +return 0 ; + + err =fetch_kfunc_meta (env, insn, &meta, &func_name); +if (err == -EACCES && func_name) +verbose (env,"calling kernel function %s is not allowed\n" , func_name); +if (err) +return err; + desc_btf = meta.btf; + insn_aux = &env->insn_aux_data[insn_idx];if (is_kfunc_destructive (&meta) && !capable (CAP_SYS_BOOT )) {verbose (env,"destructive kfunc calls require CAP_SYS_BOOT capability\n" );
@@ -9886,7 +9912,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, err =release_reference (env, regs[meta.release_regno].ref_obj_id);if (err) {verbose (env,"kfunc %s#%d reference has not been acquired before\n" , - func_name, func_id); + func_name, meta.func_id);return err; } }
@@ -9898,14 +9924,14 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, err =ref_convert_owning_non_owning (env, release_ref_obj_id);if (err) {verbose (env,"kfunc %s#%d conversion of owning ref to non-owning failed\n" , - func_name, func_id); + func_name, meta.func_id);return err; } err =release_reference (env, release_ref_obj_id);if (err) {verbose (env,"kfunc %s#%d reference has not been acquired before\n" , - func_name, func_id); + func_name, meta.func_id);return err; } }
@@ -9915,7 +9941,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, set_rbtree_add_callback_state);if (err) {verbose (env,"kfunc %s#%d failed callback verification\n" , - func_name, func_id); + func_name, meta.func_id);return err; } }
@@ -9924,7 +9950,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,mark_reg_not_init (env, regs, caller_saved[i]);/* Check return type */ - t =btf_type_skip_modifiers (desc_btf, func_proto->type,NULL ); + t =btf_type_skip_modifiers (desc_btf, meta.func_proto->type,NULL );if (is_kfunc_acquire (&meta) && !btf_type_is_struct_ptr (meta.btf, t)) {/* Only exception is bpf_obj_new_impl */
@@ -9973,11 +9999,11 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, regs[BPF_REG_0 ].btf = ret_btf; regs[BPF_REG_0 ].btf_id = ret_btf_id; - env->insn_aux_data[insn_idx].obj_new_size = ret_t->size; - env->insn_aux_data[insn_idx].kptr_struct_meta = + insn_aux->obj_new_size = ret_t->size; + insn_aux->kptr_struct_meta =btf_find_struct_meta (ret_btf, ret_btf_id); }else if (meta.func_id == special_kfunc_list[KF_bpf_obj_drop_impl]) { - env->insn_aux_data[insn_idx].kptr_struct_meta = + insn_aux->kptr_struct_meta =btf_find_struct_meta (meta.arg_obj_drop.btf, meta.arg_obj_drop.btf_id); } else if (meta.func_id == special_kfunc_list[KF_bpf_list_pop_front] ||
@@ -10066,8 +10092,8 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn, regs[BPF_REG_0 ].id = ++env->id_gen; }/* else { add_kfunc_call() ensures it is btf_type_is_void(t) } */ - nargs =btf_type_vlen (func_proto); - args = (const struct btf_param *)(func_proto +1 ); + nargs =btf_type_vlen (meta.func_proto); + args = (const struct btf_param *)(meta.func_proto +1 );for (i =0 ; i < nargs; i++) {u32 regno = i +1 ;
Signature · 1 line
2.39.2