6.6.163-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 1750/3318 ALSA: emux: prune unused parameter from snd_soundfont_load_guspatch()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oswald Buddenhagen <[email protected]>
[ Upstream commit 3f3e0dfc83d586fe9204936fccae771754a9dbc2 ]
The client parameter was not used, so eliminate it from the call chain.
Message-ID: <[email protected]>
Stable-dep-of: 34e3e04b8a17 ("ALSA: emux: Fix UAF of soundfont zones at note-on")
--- include/sound/soundfont.h | 2 +- sound/synth/emux/emux_hwdep.c | 3 +-- sound/synth/emux/emux_oss.c | 3 +-- sound/synth/emux/soundfont.c | 7 +++---- 4 files changed, 6 insertions(+), 9 deletions(-)
include/sound/soundfont.h +1 -1
@@ -89,7 +89,7 @@ struct snd_sf_list {int snd_soundfont_load (struct snd_sf_list *sflist,const void __user *data,long count,int client);int snd_soundfont_load_guspatch (struct snd_sf_list *sflist,const char __user *data, -long count,int client); +long count);int snd_soundfont_close_check (struct snd_sf_list *sflist,int client); struct snd_sf_list *snd_sf_new(struct snd_sf_callback *callback,
sound/synth/emux/emux_hwdep.c +1 -2
@@ -27,8 +27,7 @@ snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)if (patch.key ==GUS_PATCH )return snd_soundfont_load_guspatch (emu->sflist, arg, - patch.len +sizeof (patch), -TMP_CLIENT_ID ); + patch.len +sizeof (patch));if (patch.type >=SNDRV_SFNT_LOAD_INFO && patch.type <=SNDRV_SFNT_PROBE_DATA ) {
sound/synth/emux/emux_oss.c +1 -2
@@ -205,8 +205,7 @@ snd_emux_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,return -ENXIO ;if (format ==GUS_PATCH ) - rc =snd_soundfont_load_guspatch (emu->sflist, buf, count, -SF_CLIENT_NO (p->chset.port)); + rc =snd_soundfont_load_guspatch (emu->sflist, buf, count);else if (format ==SNDRV_OSS_SOUNDFONT_PATCH ) {struct soundfont_patch_info patch;if (count < (int )sizeof (patch))
sound/synth/emux/soundfont.c +3 -4
@@ -944,8 +944,7 @@ int snd_sf_vol_table[128] = {/* load GUS patch */ static int -load_guspatch (struct snd_sf_list *sflist,const char __user *data, -long count,int client) +load_guspatch (struct snd_sf_list *sflist,const char __user *data,long count) {struct patch_info patch;struct snd_soundfont *sf;
@@ -1127,11 +1126,11 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,/* load GUS patch */ int snd_soundfont_load_guspatch (struct snd_sf_list *sflist,const char __user *data, -long count,int client) +long count) {int rc;lock_preset (sflist); - rc =load_guspatch (sflist, data, count, client); + rc =load_guspatch (sflist, data, count);unlock_preset (sflist);return rc; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1751/3318 ALSA: emux: fix validation of snd_emux.num_ports
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oswald Buddenhagen <[email protected]>
[ Upstream commit 19061f35b3eaf4925960be44d870244b99df8d1d ]
Both bounds had off-by-one errors.
Message-ID: <[email protected]>
Stable-dep-of: 34e3e04b8a17 ("ALSA: emux: Fix UAF of soundfont zones at note-on")
--- sound/synth/emux/emux_seq.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/synth/emux/emux_seq.c +3 -3
@@ -65,11 +65,11 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index)return -ENODEV ; } -if (emu->num_ports <0 ) { +if (emu->num_ports <=0 ) {snd_printk (KERN_WARNING "seqports must be greater than zero\n" ); emu->num_ports =1 ; - }else if (emu->num_ports >=SNDRV_EMUX_MAX_PORTS ) { -snd_printk (KERN_WARNING "too many ports." + }else if (emu->num_ports >SNDRV_EMUX_MAX_PORTS ) { +snd_printk (KERN_WARNING "too many ports. " "limited max. ports %d\n" ,SNDRV_EMUX_MAX_PORTS ); emu->num_ports =SNDRV_EMUX_MAX_PORTS ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1752/3318 ALSA: emux: Use standard print API
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit fea1510719dd2a33e0ffa1eae6118c5437f7071d ]
Use the standard print API with dev_*() instead of the old house-baked one. It gives better information and allows dynamically control of debug prints.
Some functions are changed to receive snd_card object for calling dev_*() functions, too.
Stable-dep-of: 34e3e04b8a17 ("ALSA: emux: Fix UAF of soundfont zones at note-on")
--- include/sound/soundfont.h | 6 ++-- sound/synth/emux/emux_hwdep.c | 6 ++-- sound/synth/emux/emux_oss.c | 11 +++--- sound/synth/emux/emux_seq.c | 13 ++++--- sound/synth/emux/emux_synth.c | 12 +++---- sound/synth/emux/soundfont.c | 67 +++++++++++++++++++---------------- 6 files changed, 63 insertions(+), 52 deletions(-)
include/sound/soundfont.h +4 -2
@@ -86,9 +86,11 @@ struct snd_sf_list { };/* Prototypes for soundfont.c */ -int snd_soundfont_load (struct snd_sf_list *sflist,const void __user *data, +int snd_soundfont_load (struct snd_card *card, +struct snd_sf_list *sflist,const void __user *data,long count,int client); -int snd_soundfont_load_guspatch (struct snd_sf_list *sflist,const char __user *data, +int snd_soundfont_load_guspatch (struct snd_card *card, +struct snd_sf_list *sflist,const char __user *data,long count);int snd_soundfont_close_check (struct snd_sf_list *sflist,int client);
sound/synth/emux/emux_hwdep.c +4 -2
@@ -26,12 +26,14 @@ snd_emux_hwdep_load_patch(struct snd_emux *emu, void __user *arg)return -EFAULT ;if (patch.key ==GUS_PATCH ) -return snd_soundfont_load_guspatch (emu->sflist, arg, +return snd_soundfont_load_guspatch (emu->card, emu->sflist, arg, patch.len +sizeof (patch));if (patch.type >=SNDRV_SFNT_LOAD_INFO && patch.type <=SNDRV_SFNT_PROBE_DATA ) { - err =snd_soundfont_load (emu->sflist, arg, patch.len +sizeof (patch),TMP_CLIENT_ID ); + err =snd_soundfont_load (emu->card, emu->sflist, arg, + patch.len +sizeof (patch), +TMP_CLIENT_ID );if (err <0 )return err; }else {
sound/synth/emux/emux_oss.c +7 -4
@@ -115,7 +115,7 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure) p =snd_emux_create_port (emu, tmpname,32 ,1 , &callback);if (p ==NULL ) { -snd_printk (KERN_ERR "can't create port\n" ); +dev_err (emu->card->dev,"can't create port\n" );snd_emux_dec_count (emu);return -ENOMEM ; }
@@ -205,7 +205,7 @@ snd_emux_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,return -ENXIO ;if (format ==GUS_PATCH ) - rc =snd_soundfont_load_guspatch (emu->sflist, buf, count); + rc =snd_soundfont_load_guspatch (emu->card, emu->sflist, buf, count);else if (format ==SNDRV_OSS_SOUNDFONT_PATCH ) {struct soundfont_patch_info patch;if (count < (int )sizeof (patch))
@@ -214,10 +214,13 @@ snd_emux_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,return -EFAULT ;if (patch.type >=SNDRV_SFNT_LOAD_INFO && patch.type <=SNDRV_SFNT_PROBE_DATA ) - rc =snd_soundfont_load (emu->sflist, buf, count,SF_CLIENT_NO (p->chset.port)); + rc =snd_soundfont_load (emu->card, emu->sflist, buf, + count, +SF_CLIENT_NO (p->chset.port));else {if (emu->ops.load_fx) - rc = emu->ops.load_fx (emu, patch.type, patch.optarg, buf, count); + rc = emu->ops.load_fx (emu, patch.type, + patch.optarg, buf, count);else rc = -EINVAL ; }
sound/synth/emux/emux_seq.c +6 -7
@@ -61,16 +61,17 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index) emu->client =snd_seq_create_kernel_client (card, index,"%s WaveTable" , emu->name);if (emu->client <0 ) { -snd_printk (KERN_ERR "can't create client\n" ); +dev_err (card->dev,"can't create client\n" );return -ENODEV ; }if (emu->num_ports <=0 ) { -snd_printk (KERN_WARNING "seqports must be greater than zero\n" ); +dev_warn (card->dev,"seqports must be greater than zero\n" ); emu->num_ports =1 ; }else if (emu->num_ports >SNDRV_EMUX_MAX_PORTS ) { -snd_printk (KERN_WARNING "too many ports. " -"limited max. ports %d\n" ,SNDRV_EMUX_MAX_PORTS ); +dev_warn (card->dev, +"too many ports. limited max. ports %d\n" , +SNDRV_EMUX_MAX_PORTS ); emu->num_ports =SNDRV_EMUX_MAX_PORTS ; }
@@ -87,7 +88,7 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index) p =snd_emux_create_port (emu, tmpname,MIDI_CHANNELS ,0 , &pinfo);if (!p) { -snd_printk (KERN_ERR "can't create port\n" ); +dev_err (card->dev,"can't create port\n" );return -ENOMEM ; }
@@ -376,12 +377,10 @@ int snd_emux_init_virmidi(struct snd_emux *emu, struct snd_card *card) goto __error; } emu->vmidi[i] = rmidi; -/* snd_printk(KERN_DEBUG "virmidi %d ok\n", i); */ }return 0 ; __error: -/* snd_printk(KERN_DEBUG "error init..\n"); */ snd_emux_delete_virmidi (emu);return -ENOMEM ; }
sound/synth/emux/emux_synth.c +6 -6
@@ -942,9 +942,9 @@ void snd_emux_lock_voice(struct snd_emux *emu, int voice)if (emu->voices[voice].state ==SNDRV_EMUX_ST_OFF ) emu->voices[voice].state =SNDRV_EMUX_ST_LOCKED ;else -snd_printk (KERN_WARNING -"invalid voice for lock %d (state = %x)\n" , - voice, emu->voices[voice].state); +dev_warn (emu->card->dev, +"invalid voice for lock %d (state = %x)\n" , + voice, emu->voices[voice].state);spin_unlock_irqrestore (&emu->voice_lock, flags); }
@@ -960,9 +960,9 @@ void snd_emux_unlock_voice(struct snd_emux *emu, int voice)if (emu->voices[voice].state ==SNDRV_EMUX_ST_LOCKED ) emu->voices[voice].state =SNDRV_EMUX_ST_OFF ;else -snd_printk (KERN_WARNING -"invalid voice for unlock %d (state = %x)\n" , - voice, emu->voices[voice].state); +dev_warn (emu->card->dev, +"invalid voice for unlock %d (state = %x)\n" , + voice, emu->voices[voice].state);spin_unlock_irqrestore (&emu->voice_lock, flags); }
sound/synth/emux/soundfont.c +36 -31
165 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1753/3318 ALSA: synth: Use guard() for spin locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 59ede7178d402b3bfa0266cbd9ad348d5612c295 ]
Clean up the code using guard() for spin locks.
Merely code refactoring, and no behavior change.
Stable-dep-of: 34e3e04b8a17 ("ALSA: emux: Fix UAF of soundfont zones at note-on")
--- sound/synth/emux/emux_effect.c | 29 ++++++++-------- sound/synth/emux/emux_synth.c | 54 +++++++---------------------- sound/synth/emux/soundfont.c | 63 ++++++++++++---------------------- 3 files changed, 49 insertions(+), 97 deletions(-)
sound/synth/emux/emux_effect.c +14 -15
@@ -168,7 +168,6 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan,unsigned char *srcp, *origp;struct snd_emux *emu;struct snd_emux_effect_table *fx; -unsigned long flags; emu = port->emu; fx = chan->private;
@@ -195,22 +194,22 @@ snd_emux_send_effect(struct snd_emux_port *port, struct snd_midi_channel *chan, offset++;#endif /* modify the register values */ -spin_lock_irqsave (&emu->voice_lock, flags); -for (i =0 ; i < emu->max_voices; i++) { -struct snd_emux_voice *vp = &emu->voices[i]; -if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) -continue ; - srcp = (unsigned char *)&vp->reg.parm + offset; - origp = (unsigned char *)&vp->zone->v.parm + offset; -if (parm_defs[i].type &PARM_IS_BYTE ) { - *srcp = *origp; -effect_set_byte (srcp, chan, type); - }else { - *(unsigned short *)srcp = *(unsigned short *)origp; -effect_set_word ((unsigned short *)srcp, chan, type); + scoped_guard(spinlock_irqsave, &emu->voice_lock) { +for (i =0 ; i < emu->max_voices; i++) { +struct snd_emux_voice *vp = &emu->voices[i]; +if (!STATE_IS_PLAYING (vp->state) || vp->chan != chan) +continue ; + srcp = (unsigned char *)&vp->reg.parm + offset; + origp = (unsigned char *)&vp->zone->v.parm + offset; +if (parm_defs[i].type &PARM_IS_BYTE ) { + *srcp = *origp; +effect_set_byte (srcp, chan, type); + }else { + *(unsigned short *)srcp = *(unsigned short *)origp; +effect_set_word ((unsigned short *)srcp, chan, type); + } } } -spin_unlock_irqrestore (&emu->voice_lock, flags);/* activate them */ snd_emux_update_channel (port, chan, parm_defs[type].update);
sound/synth/emux/emux_synth.c +13 -41
250 lines not on this page · raw message
sound/synth/emux/soundfont.c +22 -41
136 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1754/3318 ALSA: emux: Fix UAF of soundfont zones at note-on
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 34e3e04b8a1731a773797542f0781e99ce7cd755 ]
snd_emux_note_on() looks up the matching zones via snd_soundfont_search_zone(), which takes sflist->lock only during the lookup and returns the raw zone pointers after releasing it. The caller then stores them in vp->zone without any protection. Meanwhile, a concurrent SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES ioctl may unlink and free those zones in snd_soundfont_remove_unlocked(); this leads to a use-after-free in snd_emux_note_on(), and later at accessing the cached vp->zone, e.g. in snd_emux_send_effect().
Fix it by holding sflist->lock in snd_emux_note_on() over the whole zone lookup and voice setup, and let snd_soundfont_search_zone() require the caller to hold the lock, instead. snd_soundfont_lock_preset() takes sflist->lock for setting presets_locked, so the removal path now syncs with the note-on finish.
--- sound/synth/emux/emux_synth.c | 3 +++ sound/synth/emux/soundfont.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
sound/synth/emux/emux_synth.c +3 -0
@@ -60,6 +60,9 @@ snd_emux_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)return ; key = note;/* remember the original note */ + +/* hold sflist->lock for protecting against concurrent free */ +guard (spinlock_irqsave)(&emu->sflist->lock); nvoices =get_zone (emu, port, ¬e, vel, chan, table);if (! nvoices)return ;
sound/synth/emux/soundfont.c +6 -3
@@ -1220,6 +1220,9 @@ delete_preset(struct snd_sf_list *sflist, struct snd_sf_zone *zp)* The found zones are stored on 'table' array. max_layers defines * the maximum number of elements in this array. * This function returns the number of found zones. 0 if not found. +* +* The caller must hold sflist->lock, and keep holding it as long as +* the returned zones are accessed. */ int snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel,
@@ -1229,11 +1232,11 @@ snd_soundfont_search_zone(struct snd_sf_list *sflist, int *notep, int vel, {int nvoices; -/* this function is supposed to be called atomically, -* so we check the lock. if it's busy, just returns 0 to +lockdep_assert_held (&sflist->lock); + +/* if the presets are being modified, just returns 0 to * tell the caller the busy state */ -guard (spinlock_irqsave)(&sflist->lock);if (sflist->presets_locked)return 0 ; nvoices = search_zones(sflist, notep, vel, preset, bank,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1755/3318 ALSA: hda/hdmi: clamp num_cvts against cvt_nids[] in hdmi_read_pin_conn
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 6cf3ab38b0d53d41f00fe594b2986849bdf994ae ]
hdmi_add_cvt() stores each converter's NID into the fixed-size spec->cvt_nids[] array (used only by the Intel Haswell pin-connection fixup), but only when spec->num_cvts is still within ARRAY_SIZE(cvt_nids); the num_cvts counter itself is incremented unconditionally regardless of whether the store happened. A codec that reports more converters than cvt_nids[] can hold therefore ends up with num_cvts > ARRAY_SIZE(cvt_nids).
hdmi_read_pin_conn(), on the intel_hsw_fixup path, copies num_cvts elements from cvt_nids[] with memcpy(), so once num_cvts exceeds the array size this reads past cvt_nids[] and writes the resulting garbage NIDs into per_pin->mux_nids[].
Clamp the copy length to the actual size of cvt_nids[] instead of trusting num_cvts, which is also used unbounded as the size of the separate, dynamically-sized spec->cvts array and must not be truncated at the source.
--- sound/pci/hda/patch_hdmi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/pci/hda/patch_hdmi.c +2 -1
@@ -1355,7 +1355,8 @@ static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)snd_hda_set_dev_select (codec, pin_nid, dev_id);if (spec->intel_hsw_fixup) { - conns = spec->num_cvts; +/* spec->cvt_nids[] only has ARRAY_SIZE(spec->cvt_nids) slots */ + conns =min_t (int, spec->num_cvts,ARRAY_SIZE (spec->cvt_nids));memcpy (per_pin->mux_nids, spec->cvt_nids,sizeof (hda_nid_t) * conns); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1756/3318 KVM: arm64: vgic: Stop the target vcpu when disabling LPIs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit a1b4bd2c2c262b8094c86afb99364d16ac08cb66 ]
Disabling LPIs is pretty nasty, as it directly messes with the AP list of the affected CPU, which could be running... This has the potential to lead to really bad behaviours, and we should not be doing that.
Take example on the way the Active state is handled and simply pause the the vcpu so that we are sure it is in a quiescent state, and the state be safely manipulated.
Nobody has any expectation of performance for this anyway.
--- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/kvm/vgic/vgic-mmio-v3.c +10 -0
@@ -276,9 +276,19 @@ static void vgic_mmio_write_v3r_ctlr(struct kvm_vcpu *vcpu,if (ctlr !=GICR_CTLR_ENABLE_LPIS )return ; +/* +* Yes, disabling LPIs is painful, since it can be done from +* a *remote* vcpu! So let's not take any chance, and make +* sure that the target vCPU has written their LRs back to the +* irq structures, and release any reference they would have. +* +* If it hurts, don't do it. +*/ +kvm_arm_halt_guest (vcpu->kvm);vgic_flush_pending_lpis (vcpu);vgic_its_invalidate_cache (vcpu->kvm);atomic_set_release (&vgic_cpu->ctlr,0 ); +kvm_arm_resume_guest (vcpu->kvm); }else { ctlr =atomic_cmpxchg_acquire (&vgic_cpu->ctlr,0 ,GICR_CTLR_ENABLE_LPIS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1757/3318 driver core: Add device_show_string() helper for sysfs attributes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
[ Upstream commit 3cc50d07be10f67aff836f8247a240ec132c6a67 ]
For drivers wishing to expose an unsigned long, int or bool at a static memory location in sysfs, the driver core provides ready-made helpers such as device_show_ulong() to be used as ->show() callback.
Some drivers need to expose a string and so far they all provide their own ->show() implementation. arch/powerpc/perf/hv-24x7.c went so far as to create a device_show_string() helper but kept it private.
Make it public for reuse by other drivers. The pattern seems to be sufficiently frequent to merit a public helper.
Add a DEVICE_STRING_ATTR_RO() macro in line with the existing DEVICE_ULONG_ATTR() and similar macros to ease declaration of string attributes.
Stable-dep-of: 3d9a175707ee ("platform/x86: asus-wmi: fix TUF keyboard power state shutdown naming")
--- arch/powerpc/perf/hv-24x7.c | 10 ---------- drivers/base/core.c | 9 +++++++++ include/linux/device.h | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-)
arch/powerpc/perf/hv-24x7.c +0 -10
@@ -425,16 +425,6 @@ static char *memdup_to_str(char *maybe_str, int max_len, gfp_t gfp)return kasprintf (gfp,"%.*s" , max_len, maybe_str); } -static ssize_t device_show_string (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct dev_ext_attribute *d; - - d = container_of(attr, struct dev_ext_attribute, attr); - -return sprintf (buf,"%s\n" , (char *)d->var); -} -static ssize_t cpumask_show (struct device *dev,struct device_attribute *attr,char *buf) {
drivers/base/core.c +9 -0
@@ -2548,6 +2548,15 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, }EXPORT_SYMBOL_GPL (device_show_bool); +ssize_t device_show_string (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct dev_ext_attribute *ea =to_ext_attr (attr); + +return sysfs_emit (buf,"%s\n" , (char *)ea->var); +} +EXPORT_SYMBOL_GPL (device_show_string); +/** * device_release - free device structure. * @kobj: device's kobject.
include/linux/device.h +15 -0
@@ -138,6 +138,8 @@ ssize_t device_show_bool(struct device *dev, struct device_attribute *attr, char *buf);ssize_t device_store_bool (struct device *dev,struct device_attribute *attr,const char *buf,size_t count); +ssize_t device_show_string (struct device *dev,struct device_attribute *attr, +char *buf);/** * DEVICE_ATTR - Define a device attribute.
@@ -257,6 +259,19 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr, struct dev_ext_attribute dev_attr_##_name = \ {__ATTR (_name, _mode, device_show_bool, device_store_bool), &(_var) } +/** +* DEVICE_STRING_ATTR_RO - Define a device attribute backed by a r/o string. +* @_name: Attribute name. +* @_mode: File mode. +* @_var: Identifier of string. +* +* Like DEVICE_ULONG_ATTR(), but @_var is a string. Because the length of the +* string allocation is unknown, the attribute must be read-only. + */ +#define DEVICE_STRING_ATTR_RO (_name, _mode, _var) \ + struct dev_ext_attribute dev_attr_##_name = \ + { __ATTR(_name, (_mode) & ~0222, device_show_string, NULL), (_var) } +#define DEVICE_ATTR_IGNORE_LOCKDEP (_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = \ __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1758/3318 platform/x86: Use device_show_string() helper for sysfs attributes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
[ Upstream commit 3182459b7bff642eb968d6203a08aea3862436c1 ]
Deduplicate sysfs ->show() callbacks which expose a string at a static memory location. Use the newly introduced device_show_string() helper in the driver core instead by declaring those sysfs attributes with DEVICE_STRING_ATTR_RO().
No functional change intended.
Stable-dep-of: 3d9a175707ee ("platform/x86: asus-wmi: fix TUF keyboard power state shutdown naming")
--- drivers/platform/x86/asus-wmi.c | 62 ++++++++--------------------- drivers/platform/x86/toshiba_acpi.c | 9 +---- 2 files changed, 18 insertions(+), 53 deletions(-)
drivers/platform/x86/asus-wmi.c +16 -46
@@ -926,17 +926,12 @@ static ssize_t kbd_rgb_mode_store(struct device *dev, }static DEVICE_ATTR_WO (kbd_rgb_mode); -static ssize_t kbd_rgb_mode_index_show (struct device *device, -struct device_attribute *attr, -char *buf) -{ -return sysfs_emit (buf,"%s\n" ,"cmd mode red green blue speed" ); -} -static DEVICE_ATTR_RO (kbd_rgb_mode_index); +static DEVICE_STRING_ATTR_RO(kbd_rgb_mode_index, 0444, + "cmd mode red green blue speed");static struct attribute *kbd_rgb_mode_attrs[] = { &dev_attr_kbd_rgb_mode.attr, - &dev_attr_kbd_rgb_mode_index.attr, + &dev_attr_kbd_rgb_mode_index.attr.attr,NULL , };
@@ -978,17 +973,12 @@ static ssize_t kbd_rgb_state_store(struct device *dev, }static DEVICE_ATTR_WO (kbd_rgb_state); -static ssize_t kbd_rgb_state_index_show (struct device *device, -struct device_attribute *attr, -char *buf) -{ -return sysfs_emit (buf,"%s\n" ,"cmd boot awake sleep keyboard" ); -} -static DEVICE_ATTR_RO (kbd_rgb_state_index); +static DEVICE_STRING_ATTR_RO(kbd_rgb_state_index, 0444, + "cmd boot awake sleep keyboard");static struct attribute *kbd_rgb_state_attrs[] = { &dev_attr_kbd_rgb_state.attr, - &dev_attr_kbd_rgb_state_index.attr, + &dev_attr_kbd_rgb_state_index.attr.attr,NULL , };
@@ -2505,13 +2495,6 @@ static ssize_t pwm1_enable_store(struct device *dev,return count; } -static ssize_t fan1_label_show (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return sysfs_emit (buf,"%s\n" ,ASUS_FAN_DESC ); -} -static ssize_t asus_hwmon_temp1 (struct device *dev,struct device_attribute *attr,char *buf)
@@ -2546,13 +2529,6 @@ static ssize_t fan2_input_show(struct device *dev,return sysfs_emit (buf,"%d\n" , value *100 ); } -static ssize_t fan2_label_show (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return sysfs_emit (buf,"%s\n" ,ASUS_GPU_FAN_DESC ); -} -/* Middle/Center fan on modern ROG laptops */ static ssize_t fan3_input_show(struct device *dev, struct device_attribute *attr,
@@ -2571,13 +2547,6 @@ static ssize_t fan3_input_show(struct device *dev,return sysfs_emit (buf,"%d\n" , value *100 ); } -static ssize_t fan3_label_show (struct device *dev, -struct device_attribute *attr, -char *buf) -{ -return sysfs_emit (buf,"%s\n" ,ASUS_MID_FAN_DESC ); -} -static ssize_t pwm2_enable_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -2674,15 +2643,16 @@ static ssize_t pwm3_enable_store(struct device *dev,static DEVICE_ATTR_RW (pwm1);static DEVICE_ATTR_RW (pwm1_enable);static DEVICE_ATTR_RO (fan1_input); -static DEVICE_ATTR_RO (fan1_label); +static DEVICE_STRING_ATTR_RO(fan1_label, 0444, ASUS_FAN_DESC); +/* Fan2 - GPU fan */ static DEVICE_ATTR_RW (pwm2_enable);static DEVICE_ATTR_RO (fan2_input); -static DEVICE_ATTR_RO (fan2_label); +static DEVICE_STRING_ATTR_RO(fan2_label, 0444, ASUS_GPU_FAN_DESC);/* Fan3 - Middle/center fan */ static DEVICE_ATTR_RW (pwm3_enable);static DEVICE_ATTR_RO (fan3_input); -static DEVICE_ATTR_RO (fan3_label); +static DEVICE_STRING_ATTR_RO(fan3_label, 0444, ASUS_MID_FAN_DESC);/* Temperature */ static DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL);
@@ -2693,11 +2663,11 @@ static struct attribute *hwmon_attributes[] = { &dev_attr_pwm2_enable.attr, &dev_attr_pwm3_enable.attr, &dev_attr_fan1_input.attr, - &dev_attr_fan1_label.attr, + &dev_attr_fan1_label.attr.attr, &dev_attr_fan2_input.attr, - &dev_attr_fan2_label.attr, + &dev_attr_fan2_label.attr.attr, &dev_attr_fan3_input.attr, - &dev_attr_fan3_label.attr, + &dev_attr_fan3_label.attr.attr, &dev_attr_temp1_input.attr,NULL
@@ -2714,17 +2684,17 @@ static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,if (asus->fan_type !=FAN_TYPE_AGFN )return 0 ; }else if (attr == &dev_attr_fan1_input.attr - || attr == &dev_attr_fan1_label.attr + || attr == &dev_attr_fan1_label.attr.attr || attr == &dev_attr_pwm1_enable.attr) {if (asus->fan_type ==FAN_TYPE_NONE )return 0 ; }else if (attr == &dev_attr_fan2_input.attr - || attr == &dev_attr_fan2_label.attr + || attr == &dev_attr_fan2_label.attr.attr || attr == &dev_attr_pwm2_enable.attr) {if (asus->gpu_fan_type ==FAN_TYPE_NONE )return 0 ; }else if (attr == &dev_attr_fan3_input.attr - || attr == &dev_attr_fan3_label.attr + || attr == &dev_attr_fan3_label.attr.attr || attr == &dev_attr_pwm3_enable.attr) {if (asus->mid_fan_type ==FAN_TYPE_NONE )return 0 ;
drivers/platform/x86/toshiba_acpi.c +2 -7
@@ -1820,12 +1820,7 @@ static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);/* * Sysfs files */ -static ssize_t version_show (struct device *dev, -struct device_attribute *attr,char *buf) -{ -return sprintf (buf,"%s\n" ,TOSHIBA_ACPI_VERSION ); -} -static DEVICE_ATTR_RO (version); +static DEVICE_STRING_ATTR_RO(version, 0444, TOSHIBA_ACPI_VERSION); static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
@@ -2434,7 +2429,7 @@ static ssize_t cooling_method_store(struct device *dev,static DEVICE_ATTR_RW (cooling_method);static struct attribute *toshiba_attributes[] = { - &dev_attr_version.attr, + &dev_attr_version.attr.attr, &dev_attr_fan.attr, &dev_attr_kbd_backlight_mode.attr, &dev_attr_kbd_type.attr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1759/3318 platform/x86: asus-wmi: fix TUF keyboard power state shutdown naming
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartu Alev <[email protected]>
[ Upstream commit 3d9a175707eeb15a2d577af1e669b98e0236719b ]
The fourth state flag of kbd_rgb_state_index is named "keyboard" and has long been treated as having no effect. In hardware the flag, BIT(7) of the payload sent to the TUF RGB state device, gates whether the keyboard backlight stays lit while the machine powers off: with the bit set the keyboard lights up white during the ACPI S5 sequence, with the bit clear the machine powers off dark. Verified by A/B testing both values on a TUF Gaming A15 (FA507NV).
Rename the fourth field and its index entry from "keyboard" to "shutdown". The write format is unchanged, the value is still positional, and the diff is two variable names and one string, so it backports cleanly.
--- drivers/platform/x86/asus-wmi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/platform/x86/asus-wmi.c +4 -4
@@ -944,10 +944,10 @@ static ssize_t kbd_rgb_state_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t count) { - u32 flags, cmd, boot, awake, sleep, keyboard; + u32 flags, cmd, boot, awake, sleep, shutdown;int err; -if (sscanf (buf,"%d %d %d %d %d" , &cmd, &boot, &awake, &sleep, &keyboard) !=5 ) +if (sscanf (buf,"%d %d %d %d %d" , &cmd, &boot, &awake, &sleep, &shutdown) !=5 )return -EINVAL ;if (cmd)
@@ -960,7 +960,7 @@ static ssize_t kbd_rgb_state_store(struct device *dev, flags |=BIT (3 );if (sleep) flags |=BIT (5 ); -if (keyboard) +if (shutdown) flags |=BIT (7 );/* 0xbd is the required default arg0 for the method. Nothing happens otherwise */
@@ -974,7 +974,7 @@ static ssize_t kbd_rgb_state_store(struct device *dev,static DEVICE_ATTR_WO (kbd_rgb_state); static DEVICE_STRING_ATTR_RO(kbd_rgb_state_index, 0444, - "cmd boot awake sleep keyboard"); + "cmd boot awake sleep shutdown");static struct attribute *kbd_rgb_state_attrs[] = { &dev_attr_kbd_rgb_state.attr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1760/3318 fbcon: Retry rotated font allocation after failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Yiqi <[email protected]>
[ Upstream commit 7935db1a4a0f83a63590a222500e5016e2f6c85e ]
fbcon_rotate_font() records the font, its geometry and the rotation in par->rotated before calling font_data_rotate(). If the allocation fails, the error path clears par->rotated.buf, but the recorded key already looks up to date, so the next call takes the early-out and never retries. The rotated putcs/cursor ops keep returning early on the NULL buffer, and the console stays blank even after memory is available again.
Also test par->rotated.buf in the early-out, so a failed allocation is retried on the next call: at the next fbcon_switch(), fbcon_modechanged() or font change.
--- drivers/video/fbdev/core/fbcon_rotate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbcon_rotate.c +2 -1
@@ -27,7 +27,8 @@ static int fbcon_rotate_font(struct fb_info *info, struct vc_data *vc)u8 *dst;if (vc->vc_font.data == par->fontdata && - par->p->con_rotate == par->cur_rotate) + par->p->con_rotate == par->cur_rotate && + par->fontbuffer) goto finished; src = par->fontdata = vc->vc_font.data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1761/3318 xen/gntdev: Fix gntdev_dmabuf ref leak in dmabuf_exp_wait_released()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 6f165abe2b40ede71c98956cd74cd17c18505e75 ]
dmabuf_exp_wait_released() takes a reference on the exported gntdev_dmabuf with dmabuf_exp_wait_obj_get_dmabuf() and passes it to dmabuf_exp_wait_obj_new(), which drops that reference after adding the wait object to the wait list. When the wait object allocation fails, dmabuf_exp_wait_obj_new() returns ERR_PTR(-ENOMEM) early and the reference is never dropped, leaking a reference to the exported gntdev_dmabuf.
Drop the reference on the allocation failure path so the reference is consumed whether the wait object is created or not.
Message-ID: <[email protected]>
--- drivers/xen/gntdev-dmabuf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/gntdev-dmabuf.c +3 -1
@@ -96,8 +96,10 @@ dmabuf_exp_wait_obj_new(struct gntdev_dmabuf_priv *priv,struct gntdev_dmabuf_wait_obj *obj; obj =kzalloc (sizeof (*obj),GFP_KERNEL ); -if (!obj) +if (!obj) { +kref_put (&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release);return ERR_PTR (-ENOMEM ); + }init_completion (&obj->completion); obj->gntdev_dmabuf = gntdev_dmabuf;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1762/3318 mm/mlock: use a long for the page count in mlock_fixup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nickolai Zeldovich <[email protected]>
[ Upstream commit 3ae91e3079b1504ef162b2884454d5f1421f4eb9 ]
mlock_fixup() adjusts mm->locked_vm, an unsigned long, by the number of pages whose VM_LOCKED state it changes, but computes that number in an int:
int nr_pages; ... nr_pages = (end - start) >> PAGE_SHIFT; ... mm->locked_vm += nr_pages;
When a single VMA range of 2^31 pages (8 TiB with 4 KiB pages) or more is locked or unlocked, the count is truncated to 32 bits and then sign-extended, so locked_vm is changed by the wrong amount, while munmap(), mremap() and the other paths that maintain locked_vm use the full unsigned long page count.
Such a range is reachable on 64-bit architectures with a 47-bit or larger user address space (x86_64, arm64 with 48-bit VA, riscv64 Sv48) by a task with CAP_IPC_LOCK or a raised RLIMIT_MEMLOCK, which do_mlock() checks against the full untruncated length. It costs nothing with MAP_NORESERVE and MLOCK_ONFAULT/MCL_ONFAULT, since then no page is populated. On x86_64, after
p = mmap(NULL, 8UL << 40, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); mlock2(p, 8UL << 40, MLOCK_ONFAULT);
VmLck in /proc/self/status reads 18446744065119617024 kB instead of 8589934592 kB; munmap() of the region then subtracts the true size and leaves VmLck at 18446744056529682432 kB instead of 0. With 16 TiB, locked_vm is not changed at all, VmLck stays 0 kB, and after the task drops CAP_IPC_LOCK or lowers RLIMIT_MEMLOCK, mlock(), mmap(MAP_LOCKED) and the other mlock_future_ok() and account_locked_vm() users enforce RLIMIT_MEMLOCK against that count, so they let the task lock memory beyond its limit (or, in the 8 TiB case, refuse every further lock). The error persists for the life of the mm; unlocking the range in pieces skews it further. The wrong count is per-mm accounting only: it does not change which pages are locked.
The int has been there since before git history (the variable was named "pages" until it was renamed in 2.6.28); every other updater of locked_vm uses an unsigned long or long count. Make nr_pages a long, which holds the page count of any user range and its negation, so the existing sign handling is unchanged.
Found by formal verification of mm/mlock.c against the kernel binary.
--- mm/mlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mlock.c +1 -1
@@ -415,7 +415,7 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma, {struct mm_struct *mm = vma->vm_mm;pgoff_t pgoff; -int nr_pages; +long nr_pages;int ret =0 ;vm_flags_t oldflags = vma->vm_flags;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1763/3318 drm/amdgpu: Use (v)memdup_array_user in amdgpu_cs_pass1
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tvrtko Ursulin <[email protected]>
[ Upstream commit d4b6274cbf0b0ee92294d699f138b63aa4796ad0 ]
Replace k(v)malloc_array() + copy_from_user() with (v)memdup_array_user().
This shrinks the source code and improves separation between the kernel and userspace slabs.
Stable-dep-of: ba4c3c202919 ("drm/amdgpu: reject CS chunks too large for kvmalloc()")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 33 ++++++++------------------ 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -23
@@ -202,25 +202,17 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,struct amdgpu_fpriv *fpriv = p->filp->driver_priv;unsigned int num_ibs[AMDGPU_CS_GANG_SIZE ] = { };struct amdgpu_vm *vm = &fpriv->vm; -uint64_t *chunk_array_user;uint64_t *chunk_array;uint32_t uf_offset =0 ;size_t size;int ret;int i; - chunk_array =kvmalloc_array (cs->in.num_chunks,sizeof (uint64_t ), -GFP_KERNEL ); -if (!chunk_array) -return -ENOMEM ; - -/* get chunks */ - chunk_array_user =u64_to_user_ptr (cs->in.chunks); -if (copy_from_user (chunk_array, chunk_array_user, -sizeof (uint64_t )*cs->in.num_chunks)) { - ret = -EFAULT ; - goto free_chunk; - } + chunk_array =memdup_array_user (u64_to_user_ptr (cs->in.chunks), + cs->in.num_chunks, +sizeof (uint64_t )); +if (IS_ERR (chunk_array)) +return PTR_ERR (chunk_array); p->nchunks = cs->in.num_chunks; p->chunks = kvmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
@@ -233,7 +225,6 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,for (i =0 ; i < p->nchunks; i++) {struct drm_amdgpu_cs_chunk __user *chunk_ptr =NULL ;struct drm_amdgpu_cs_chunk user_chunk; -uint32_t __user *cdata; chunk_ptr =u64_to_user_ptr (chunk_array[i]); if (copy_from_user(&user_chunk, chunk_ptr,
@@ -246,20 +237,16 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, p->chunks[i].length_dw = user_chunk.length_dw; size = p->chunks[i].length_dw; - cdata =u64_to_user_ptr (user_chunk.chunk_data); - p->chunks[i].kdata =kvmalloc_array (size,sizeof (uint32_t ), -GFP_KERNEL ); -if (p->chunks[i].kdata ==NULL ) { - ret = -ENOMEM ; + p->chunks[i].kdata =vmemdup_array_user (u64_to_user_ptr (user_chunk.chunk_data), + size, +sizeof (uint32_t )); +if (IS_ERR (p->chunks[i].kdata)) { + ret =PTR_ERR (p->chunks[i].kdata); i--; goto free_partial_kdata; } size *=sizeof (uint32_t ); -if (copy_from_user (p->chunks[i].kdata, cdata, size)) { - ret = -EFAULT ; - goto free_partial_kdata; - }/* Assume the worst on the following checks */ ret = -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1764/3318 drm/amdgpu: reject CS chunks too large for kvmalloc()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit ba4c3c202919405f461a393e823e4b72c8518494 ]
The CS ioctl copies every chunk with vmemdup_array_user() before it looks at it, for whatever length_dw userspace gives. kvmalloc() warns about allocations above INT_MAX when called without __GFP_NOWARN, so any process with the render node can trigger a warning. On navi31, a CS with a chunk of length_dw 0x20000000 returns -ENOMEM after:
WARNING: mm/slub.c:6841 at __kvmalloc_node_noprof+0x5a5/0x7d0
Reject such chunks with -EINVAL before trying to copy them.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -0
@@ -238,6 +238,12 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p, size = p->chunks[i].length_dw; +if (size >INT_MAX /sizeof (uint32_t )) { + ret = -EINVAL ; + i--; + goto free_partial_kdata; + } + p->chunks[i].kdata =vmemdup_array_user (u64_to_user_ptr (user_chunk.chunk_data), size,sizeof (uint32_t ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1765/3318 ALSA: emu10k1: prune vestiges of SNDRV_SFNT_SAMPLE_{BIDIR,REVERSE}_LOOP support
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oswald Buddenhagen <[email protected]>
[ Upstream commit 1edeac6555e9df008b1729ca445868c1177baa8b ]
This is required only to implement WAVE_BIDIR_LOOP and WAVE_LOOP_BACK in the GUS patch loader. It has not worked on emu10k1 since before ALSA hit mainline, yet nobody appears to have complained. And as it isn't super easy to implement, just admit defeat and clean up the code.
If somebody wanted to resurrect the feature, the emu8k driver could serve as a template, but the code would be quite different. But arguably, this should be done in user space in the first place, as this doesn't represent a hardware feature (somewhat ironically, the actual GUS driver has no synth support, and therefore no GUS patch loader).
Note that instead of properly rejecting affected samples, we continue to just pretend that the feature wasn't requested. This is extremely questionable behavior, but avoids that possibly unused instruments suddenly prevent loading the entire file, which would break backwards compatibility. But at least we log a warning now.
Message-ID: <[email protected]>
Stable-dep-of: 8a5d87c2ba30 ("ALSA: emux: Stop voices before freeing zones in all cases")
--- sound/pci/emu10k1/emu10k1_patch.c | 73 ++++--------------------------- 1 file changed, 8 insertions(+), 65 deletions(-)
sound/pci/emu10k1/emu10k1_patch.c +8 -65
@@ -28,8 +28,6 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp, {int offset;int truesize, size, blocksize; -__maybe_unused int loopsize; -int loopend, sampleend;unsigned int start_addr;struct snd_emu10k1 *emu;
@@ -43,32 +41,24 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,return 0 ; } +if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP |SNDRV_SFNT_SAMPLE_REVERSE_LOOP )) { +/* should instead return -ENOTSUPP; but compatibility */ +printk (KERN_WARNING "Emu10k1 wavetable patch %d with unsupported loop feature\n" , + sp->v.sample); + } +/* recalculate address offset */ sp->v.end -= sp->v.start; sp->v.loopstart -= sp->v.start; sp->v.loopend -= sp->v.start; sp->v.start =0 ; -/* some samples have invalid data. the addresses are corrected in voice info */ - sampleend = sp->v.end; -if (sampleend > sp->v.size) - sampleend = sp->v.size; - loopend = sp->v.loopend; -if (loopend > sampleend) - loopend = sampleend; -/* be sure loop points start < end */ if (sp->v.loopstart >= sp->v.loopend)swap (sp->v.loopstart, sp->v.loopend);/* compute true data size to be loaded */ truesize = sp->v.size +BLANK_HEAD_SIZE ; - loopsize =0 ; -#if 0 /* not supported */ -if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP |SNDRV_SFNT_SAMPLE_REVERSE_LOOP )) - loopsize = sp->v.loopend - sp->v.loopstart; - truesize += loopsize; -#endif if (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_NO_BLANK ) truesize +=BLANK_LOOP_SIZE ;
@@ -96,8 +86,8 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,snd_emu10k1_synth_bzero (emu, sp->block, offset, size); offset += size; -/* copy start->loopend */ - size = loopend; +/* copy provided samples */ + size = sp->v.size;if (! (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_8BITS )) size *=2 ;if (offset + size > blocksize)
@@ -108,53 +98,6 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,return -EFAULT ; } offset += size; - data += size; - -#if 0 /* not supported yet */ -/* handle reverse (or bidirectional) loop */ -if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP |SNDRV_SFNT_SAMPLE_REVERSE_LOOP )) { -/* copy loop in reverse */ -if (! (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_8BITS )) { -int woffset; -unsigned short *wblock = (unsigned short *)block; - woffset = offset /2 ; -if (offset + loopsize *2 > blocksize) -return -EINVAL ; -for (i =0 ; i < loopsize; i++) - wblock[woffset + i] = wblock[woffset - i -1 ]; - offset += loopsize *2 ; - }else { -if (offset + loopsize > blocksize) -return -EINVAL ; -for (i =0 ; i < loopsize; i++) - block[offset + i] = block[offset - i -1 ]; - offset += loopsize; - } - -/* modify loop pointers */ -if (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_BIDIR_LOOP ) { - sp->v.loopend += loopsize; - }else { - sp->v.loopstart += loopsize; - sp->v.loopend += loopsize; - } -/* add sample pointer */ - sp->v.end += loopsize; - } -#endif - -/* loopend -> sample end */ - size = sp->v.size - loopend; -if (size <0 ) -return -EINVAL ; -if (! (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_8BITS )) - size *=2 ; -if (snd_emu10k1_synth_copy_from_user (emu, sp->block, offset, data, size)) { -snd_emu10k1_synth_free (emu, sp->block); - sp->block =NULL ; -return -EFAULT ; - } - offset += size;/* clear rest of samples (if any) */ if (offset < blocksize)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1766/3318 ALSA: emux: centralize & improve patch info validation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oswald Buddenhagen <[email protected]>
[ Upstream commit de67aab120d4d5ba7d9e94ee5b25464ae0d1bd0e ]
This does several closely related things:
- Move the code from the drivers into the SoundFont loader, which de-duplicates it.
- Sort of explain the weird "recalculate address offset" feature. Note that I don't think it actually makes any sense - the calling user space code should do that. The background is certainly that the source data (the SoundFont format) uses pointers into a single wave block (and the API allows doing the same for on-board ROM), but the API expects the wave data from user space to be pre-chopped into individual patches anyway.
- Make sure that the specified offsets actually lie within the supplied wave data. Note that we don't validate ROM offsets, so one can play back anything within the sound card's address space.
- In load_guspatch(), don't call the sample_new callback anymore when the patch size is zero, as was already the case in load_data(). The callbacks would instantly return in that case anyway; these checks are now removed.
Message-ID: <[email protected]>
Stable-dep-of: 8a5d87c2ba30 ("ALSA: emux: Stop voices before freeing zones in all cases")
--- sound/isa/sb/emu8000_patch.c | 13 ----------- sound/pci/emu10k1/emu10k1_patch.c | 16 ------------- sound/synth/emux/soundfont.c | 37 ++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 30 deletions(-)
sound/isa/sb/emu8000_patch.c +0 -13
@@ -148,13 +148,6 @@ snd_emu8000_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,if (snd_BUG_ON (!sp))return -EINVAL ; -if (sp->v.size ==0 ) -return 0 ; - -/* be sure loop points start < end */ -if (sp->v.loopstart > sp->v.loopend) -swap (sp->v.loopstart, sp->v.loopend); -/* compute true data size to be loaded */ truesize = sp->v.size;if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP |SNDRV_SFNT_SAMPLE_REVERSE_LOOP ))
@@ -177,12 +170,6 @@ snd_emu8000_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,return -EFAULT ; } -/* recalculate address offset */ - sp->v.end -= sp->v.start; - sp->v.loopstart -= sp->v.start; - sp->v.loopend -= sp->v.start; - sp->v.start =0 ; -/* dram position (in word) -- mem_offset is byte */ dram_offset =EMU8000_DRAM_OFFSET + (sp->block->offset >>1 ); dram_start = dram_offset;
sound/pci/emu10k1/emu10k1_patch.c +0 -16
@@ -35,28 +35,12 @@ snd_emu10k1_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,if (snd_BUG_ON (!sp || !hdr))return -EINVAL ; -if (sp->v.size ==0 ) { -dev_dbg (emu->card->dev, -"emu: rom font for sample %d\n" , sp->v.sample); -return 0 ; - } -if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP |SNDRV_SFNT_SAMPLE_REVERSE_LOOP )) {/* should instead return -ENOTSUPP; but compatibility */ printk (KERN_WARNING "Emu10k1 wavetable patch %d with unsupported loop feature\n" , sp->v.sample); } -/* recalculate address offset */ - sp->v.end -= sp->v.start; - sp->v.loopstart -= sp->v.start; - sp->v.loopend -= sp->v.start; - sp->v.start =0 ; - -/* be sure loop points start < end */ -if (sp->v.loopstart >= sp->v.loopend) -swap (sp->v.loopstart, sp->v.loopend); -/* compute true data size to be loaded */ truesize = sp->v.size +BLANK_HEAD_SIZE ;if (sp->v.mode_flags &SNDRV_SFNT_SAMPLE_NO_BLANK )
sound/synth/emux/soundfont.c +36 -1
@@ -677,6 +677,21 @@ find_sample(struct snd_soundfont *sf, int sample_id) } +static int +validate_sample_info (struct soundfont_sample_info *si) +{ +if (si->end <0 || si->end > si->size) +return -EINVAL ; +if (si->loopstart <0 || si->loopstart > si->end) +return -EINVAL ; +if (si->loopend <0 || si->loopend > si->end) +return -EINVAL ; +/* be sure loop points start < end */ +if (si->loopstart > si->loopend) +swap (si->loopstart, si->loopend); +return 0 ; +} +/* * Load sample information, this can include data to be loaded onto * the soundcard. It can also just be a pointer into soundcard ROM.
@@ -718,6 +733,21 @@ load_data(struct snd_sf_list *sflist, const void __user *data, long count)return -EINVAL ; } +if (sample_info.size >0 ) { +if (sample_info.start <0 ) +return -EINVAL ; + +// Here we "rebase out" the start address, because the +// real start is the start of the provided sample data. + sample_info.end -= sample_info.start; + sample_info.loopstart -= sample_info.start; + sample_info.loopend -= sample_info.start; + sample_info.start =0 ; + +if (validate_sample_info (&sample_info) <0 ) +return -EINVAL ; + } +/* Allocate a new sample structure */ sp =sf_sample_new (sflist, sf);if (!sp)
@@ -968,6 +998,11 @@ load_guspatch(struct snd_card *card, smp->v.loopend = patch.loop_end; smp->v.size = patch.len; +if (validate_sample_info (&smp->v) <0 ) { +sf_sample_delete (sflist, sf, smp); +return -EINVAL ; + } +/* set up mode flags */ smp->v.mode_flags =0 ;if (!(patch.mode &WAVE_16_BITS ))
@@ -1005,7 +1040,7 @@ load_guspatch(struct snd_card *card,/* * load wave data */ -if (sflist->callback.sample_new) { +if (smp->v.size >0 && sflist->callback.sample_new) { rc = sflist->callback.sample_new (sflist->callback.private_data, smp, sflist->memhdr, data, count);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1767/3318 ALSA: emux: simplify snd_sf_list.callback handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oswald Buddenhagen <[email protected]>
[ Upstream commit 4c4cbe66828f185903d2127aed6ac9b7302e9d3a ]
Both drivers provide both sample_new and sample_free, and it makes no sense to pretend that they could not. In fact, load_data() would already crash if sample_new was null. So remove the remaining null checks.
Contrary to that, the emu10k1 driver actually has a null sample_reset, though I'm not convinced that this inconsistency is justified.
Message-ID: <[email protected]>
Stable-dep-of: 8a5d87c2ba30 ("ALSA: emux: Stop voices before freeing zones in all cases")
--- sound/synth/emux/emux.c | 6 ++---- sound/synth/emux/soundfont.c | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-)
sound/synth/emux/emux.c +2 -4
@@ -94,10 +94,8 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch/* create soundfont list */ memset (&sf_cb,0 ,sizeof (sf_cb)); sf_cb.private_data = emu; -if (emu->ops.sample_new) - sf_cb.sample_new = sf_sample_new; -if (emu->ops.sample_free) - sf_cb.sample_free = sf_sample_free; + sf_cb.sample_new = sf_sample_new; + sf_cb.sample_free = sf_sample_free;if (emu->ops.sample_reset) sf_cb.sample_reset = sf_sample_reset; emu->sflist =snd_sf_new (&sf_cb, emu->memhdr);
sound/synth/emux/soundfont.c +5 -7
@@ -1040,7 +1040,7 @@ load_guspatch(struct snd_card *card,/* * load wave data */ -if (smp->v.size >0 && sflist->callback.sample_new) { +if (smp->v.size >0 ) { rc = sflist->callback.sample_new (sflist->callback.private_data, smp, sflist->memhdr, data, count);
@@ -1405,9 +1405,8 @@ snd_sf_clear(struct snd_sf_list *sflist) }for (sp = sf->samples; sp; sp = nextsp) { nextsp = sp->next; -if (sflist->callback.sample_free) - sflist->callback.sample_free (sflist->callback.private_data, - sp, sflist->memhdr); + sflist->callback.sample_free (sflist->callback.private_data, + sp, sflist->memhdr);kfree (sp); }kfree (sf);
@@ -1509,9 +1508,8 @@ snd_soundfont_remove_unlocked(struct snd_sf_list *sflist) nextsp = sp->next; sf->samples = nextsp; sflist->mem_used -= sp->v.truesize; -if (sflist->callback.sample_free) - sflist->callback.sample_free (sflist->callback.private_data, - sp, sflist->memhdr); + sflist->callback.sample_free (sflist->callback.private_data, + sp, sflist->memhdr);kfree (sp); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1768/3318 ALSA: emux: Stop voices before freeing zones in all cases
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 8a5d87c2ba30e8de31cfbe888fd4d95f43c63db9 ]
The emux voice caches the soundfont zone pointer in vp->zone, which is referred to later, e.g. in snd_emux_send_effect(). For avoiding dangling pointers, the soundfont code calls the sample_reset callback to stop all voices before freeing zones. However, in a few cases (e.g. emu10k1's missing sample_reset or the call path via remove_info()), the sample reset isn't called properly, leaving the playing voices.
Fix it by always registering the sample_reset callback, falling back to snd_emux_terminate_all() when the driver has no own ops, and by calling sample_reset in remove_info() before freeing the zones.
--- sound/synth/emux/emux.c | 10 +++++++--- sound/synth/emux/soundfont.c | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-)
sound/synth/emux/emux.c +7 -3
@@ -71,7 +71,12 @@ static int sf_sample_free(void *private_data, struct snd_sf_sample *sp,static void sf_sample_reset (void *private_data) {struct snd_emux *emu = private_data; - emu->ops.sample_reset (emu); + +/* stop all voices that might refer to zones and samples to be freed */ +if (emu->ops.sample_reset) + emu->ops.sample_reset (emu); +else +snd_emux_terminate_all (emu); }int snd_emux_register (struct snd_emux *emu,struct snd_card *card,int index,char *name)
@@ -96,8 +101,7 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch sf_cb.private_data = emu; sf_cb.sample_new = sf_sample_new; sf_cb.sample_free = sf_sample_free; -if (emu->ops.sample_reset) - sf_cb.sample_reset = sf_sample_reset; + sf_cb.sample_reset = sf_sample_reset; emu->sflist =snd_sf_new (&sf_cb, emu->memhdr);if (emu->sflist ==NULL )return -ENOMEM ;
sound/synth/emux/soundfont.c +9 -0
@@ -470,6 +470,15 @@ remove_info(struct snd_sf_list *sflist, struct snd_soundfont *sf,struct snd_sf_zone *prev, *next, *p;int removed =0 ; +/* stop voices before freeing the zones they might refer to */ +for (p = sf->zones; p; p = p->next) { +if (!p->mapped && p->bank == bank && p->instr == instr) { +if (sflist->callback.sample_reset) + sflist->callback.sample_reset (sflist->callback.private_data); +break ; + } + } + prev =NULL ;for (p = sf->zones; p; p = next) { next = p->next;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1769/3318 nvmem: rockchip-otp: alloc clks with main struct
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit 9f99bb979f930e52e6861114fe03535d4bc2f374 ]
Use a flexible array member to simplify allocation slightly. No need for a separate calloc.
Stable-dep-of: 9fc6a1592d84 ("nvmem: rockchip-otp: Serialize reads")
--- drivers/nvmem/rockchip-otp.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/nvmem/rockchip-otp.c +2 -7
@@ -77,9 +77,9 @@ struct rockchip_data {struct rockchip_otp {struct device *dev;void __iomem *base; -struct clk_bulk_data *clks;struct reset_control *rst;const struct rockchip_data *data; +struct clk_bulk_data clks[]; };static int rockchip_otp_reset (struct rockchip_otp *otp)
@@ -326,7 +326,7 @@ static int rockchip_otp_probe(struct platform_device *pdev)if (!data)return dev_err_probe (dev, -EINVAL ,"failed to get match data\n" ); - otp =devm_kzalloc (&pdev->dev,sizeof (struct rockchip_otp ), + otp =devm_kzalloc (&pdev->dev,struct_size (otp, clks, data->num_clks),GFP_KERNEL );if (!otp)return -ENOMEM ;
@@ -338,11 +338,6 @@ static int rockchip_otp_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (otp->base),"failed to ioremap resource\n" ); - otp->clks =devm_kcalloc (dev, data->num_clks,sizeof (*otp->clks), -GFP_KERNEL ); -if (!otp->clks) -return -ENOMEM ; -for (i =0 ; i < data->num_clks; ++i) otp->clks[i].id = data->clks[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1770/3318 nvmem: rockchip-otp: Serialize reads
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit 9fc6a1592d844c0397f115ee8cbd935169b9a71e ]
The OTP controller is driven through a single set of registers holding a state machine which has to be stepped through for every word read, yet nothing keeps two readers out of each other's way. Concurrent reads interleave, and the outcome is either a reader bailing out:
rockchip-otp 2a580000.otp: timeout during read setup
or, worse, one of them silently taking delivery of the other's data.
Reading two cells in parallel from userspace on RK3576 reproduces both within 150 iterations - 53 read errors and 9 corrupted results, the latter either losing their first word or, in one case, ending in the two bytes which belong to the other reader's cell - whereas the same reads issued sequentially never fail. Concurrency is not hypothetical here, as six thermal sensors source their trim values from the OTP and reach the driver straight from asynchronous driver probing.
Guard the read path with a mutex. Reads are the only way into the hardware, as the driver registers no write callback, and they always run in process context, so a plain mutex spanning the whole clock-enable, read, clock-disable sequence is enough.
--- drivers/nvmem/rockchip-otp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/nvmem/rockchip-otp.c +14 -1
@@ -12,6 +12,7 @@#include <linux/io.h> #include <linux/iopoll.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/nvmem-provider.h> #include <linux/reset.h> #include <linux/slab.h>
@@ -79,6 +80,8 @@ struct rockchip_otp {void __iomem *base;struct reset_control *rst;const struct rockchip_data *data; +/* Serializes access to the OTP controller state machine */ +struct mutex mutex;struct clk_bulk_data clks[]; };
@@ -239,16 +242,21 @@ static int rockchip_otp_read(void *context, unsigned int offset,if (!otp->data || !otp->data->reg_read)return -EINVAL ; +mutex_lock (&otp->mutex); + ret =clk_bulk_prepare_enable (otp->data->num_clks, otp->clks);if (ret <0 ) {dev_err (otp->dev,"failed to prepare/enable clks\n" ); -return ret; + goto unlock; } ret = otp->data->reg_read (context, offset, val, bytes);clk_bulk_disable_unprepare (otp->data->num_clks, otp->clks); +unlock: +mutex_unlock (&otp->mutex); +return ret; }
@@ -333,6 +341,11 @@ static int rockchip_otp_probe(struct platform_device *pdev) otp->data = data; otp->dev = dev; + + ret =devm_mutex_init (dev, &otp->mutex); +if (ret) +return ret; + otp->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (otp->base)) return dev_err_probe(dev, PTR_ERR(otp->base),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1771/3318 hwmon: (acpi_power_meter) Fix 18.45 TW bug
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
[ Upstream commit 0b6eda22f9ab67ddb2a872b0c3fc578ad9f4e27e ]
The ACPI specification says:
"If an error occurs while obtaining the meter reading or if the value is not available then an Integer with all bits set is returned"
This integer can also be 64-bit wide on ACPI 2.0 and later systems, so we have to check for that too.
Compile-tested only.
--- drivers/hwmon/acpi_power_meter.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +8 -2
@@ -10,6 +10,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/jiffies.h> +#include <linux/limits.h> #include <linux/mutex.h> #include <linux/dmi.h> #include <linux/slab.h>
@@ -31,7 +32,12 @@#define POWER_METER_CAN_NOTIFY (1 << 3)#define POWER_METER_IS_BATTERY (1 << 8)#define UNKNOWN_HYSTERESIS 0xFFFFFFFF -#define UNKNOWN_POWER 0xFFFFFFFF +/* +* ACPI integers can either be 32-bit or 64-bit wide, so +* we have to check for both values. +*/ +#define UNKNOWN_POWER_32 U32_MAX +#define UNKNOWN_POWER_64 U64_MAX#define METER_NOTIFY_CONFIG 0x80#define METER_NOTIFY_TRIP 0x81
@@ -349,7 +355,7 @@ static ssize_t show_power(struct device *dev,update_meter (resource);mutex_unlock (&resource->lock); -if (resource->power ==UNKNOWN_POWER ) +if (resource->power ==UNKNOWN_POWER_32 || resource->power ==UNKNOWN_POWER_64 )return -ENODATA ;return sprintf (buf,"%llu\n" , resource->power *1000 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1772/3318 drm/amdgpu: reset SI ASIC on MacBookPros with VRAM at 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maciej Kucharek <[email protected]>
[ Upstream commit 5b56ede880317bd912f914d5cd38ba1d357677fa ]
On MacBookPros with switchable graphics, the firmware puts VRAM at MC address 0 when the iGPU is enabled. The EFI stub enables the iGPU on these machines through apple_set_os(). On a MacBookPro11,5 (Radeon R9 M370X, 1002:6821, subsystem 106b:0149), the driver adopts this layout at init:
MC_VM_FB_LOCATION=0x007f0000, HDP_NONSURFACE_BASE=0 VRAM at 0x0-0x7fffffff, GART table at 0x1400000
The driver posts the ASIC again on S3 resume and after a GPU reset. The VBIOS asic_init table then moves VRAM back to the VBIOS default:
MC_VM_FB_LOCATION=0xf47ff400, HDP_NONSURFACE_BASE=0xf4000000
gmc_v6_0 does not reprogram these registers. The GART table is then no longer in VRAM, and the gfx ring test times out:
amdgpu: ring gfx test failed (-110)
amdgpu: resume of IP block <gfx_v6_0> failed -110
Reset and post the ASIC at driver load on Apple boards with VRAM at 0. The driver then uses the VBIOS layout (VRAM at 0xf400000000) from the start, and later posts keep it. After the reset, FB_BASE is not 0, so a module reload does not reset the ASIC again.
The test is the same one that commit c54e4d105077 ("drm/amdgpu: make Mac FB workaround generic") uses: an Apple subsystem vendor and VRAM at
0. The VI quirk for the MacBookPro14,3 resets at load for the same reason:
commit b6b1d9721851 ("drm/amdgpu: reset VI ASIC on MacBookPro14,3")
Other Apple SI boards get the same reset if FB_BASE reads 0 at load.
Tested on a MacBookPro11,5 with 7.2.5 and this patch: the panel comes up at boot, and 4 of 4 deep S3 cycles resume. Without the patch, S3 resume fails every time. The GPU reset path is not tested.
--- drivers/gpu/drm/amd/amdgpu/si.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/amdgpu/si.c +10 -0
@@ -1509,6 +1509,16 @@ static bool si_need_full_reset(struct amdgpu_device *adev)static bool si_need_reset_on_init (struct amdgpu_device *adev) { +/* +* MacBookPros with switchable graphics put VRAM at 0 when the iGPU +* is enabled. Any later post (S3 resume, GPU reset) moves it back to +* the vbios default, so reset and post on load to start with the +* vbios layout. +*/ +if (adev->pdev->subsystem_vendor ==PCI_VENDOR_ID_APPLE && + !(RREG32 (mmMC_VM_FB_LOCATION) &0xFFFF )) +return true; +return false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1773/3318 Input: matrix_keypad - convert to platform remove callback returning void
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit af90388a598d39584283c18e4047124fee8f1801 ]
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 ignored (apart from emitting a warning) 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. Eventually after all drivers are converted, .remove_new() will be renamed to .remove().
Trivially convert this driver from always returning zero in the remove callback to the void returning variant.
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
--- drivers/input/keyboard/matrix_keypad.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/input/keyboard/matrix_keypad.c +2 -4
@@ -549,15 +549,13 @@ static int matrix_keypad_probe(struct platform_device *pdev)return err; } -static int matrix_keypad_remove (struct platform_device *pdev) +static void matrix_keypad_remove (struct platform_device *pdev) {struct matrix_keypad *keypad =platform_get_drvdata (pdev);matrix_keypad_free_gpio (keypad);input_unregister_device (keypad->input_dev);kfree (keypad); - -return 0 ; }#ifdef CONFIG_OF
@@ -570,7 +568,7 @@ MODULE_DEVICE_TABLE(of, matrix_keypad_dt_match);static struct platform_driver matrix_keypad_driver = { .probe = matrix_keypad_probe, - .remove = matrix_keypad_remove, + .remove_new = matrix_keypad_remove, .driver = { .name ="matrix-keypad" , .pm =pm_sleep_ptr (&matrix_keypad_pm_ops),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1774/3318 Input: matrix_keypad - avoid repeatedly converting GPIO to IRQ
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit a96fb711c6be76bcfbcf594a865002fa7c0eb525 ]
There is no need to do conversion from GPIOs to interrupt numbers. Convert row GPIOs to interrupt numbers once in probe() and use this information when the driver needs to enable or disable given interrupt line.
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
--- drivers/input/keyboard/matrix_keypad.c | 48 ++++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-)
drivers/input/keyboard/matrix_keypad.c +25 -23
@@ -27,6 +27,7 @@ struct matrix_keypad {const struct matrix_keypad_platform_data *pdata;struct input_dev *input_dev;unsigned int row_shift; +unsigned int row_irqs[MATRIX_MAX_ROWS ];DECLARE_BITMAP (disabled_gpios,MATRIX_MAX_ROWS );
@@ -92,7 +93,7 @@ static void enable_row_irqs(struct matrix_keypad *keypad)enable_irq (pdata->clustered_irq); else {for (i =0 ; i < pdata->num_row_gpios; i++) -enable_irq (gpio_to_irq (pdata->row_gpios[i])); +enable_irq (keypad->row_irqs[i]); } }
@@ -105,7 +106,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad)disable_irq_nosync (pdata->clustered_irq); else {for (i =0 ; i < pdata->num_row_gpios; i++) -disable_irq_nosync (gpio_to_irq (pdata->row_gpios[i])); +disable_irq_nosync (keypad->row_irqs[i]); } }
@@ -233,7 +234,6 @@ static void matrix_keypad_stop(struct input_dev *dev)static void matrix_keypad_enable_wakeup (struct matrix_keypad *keypad) {const struct matrix_keypad_platform_data *pdata = keypad->pdata; -unsigned int gpio;int i;if (pdata->clustered_irq >0 ) {
@@ -241,21 +241,16 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) keypad->gpio_all_disabled = true; }else { -for (i =0 ; i < pdata->num_row_gpios; i++) { -if (!test_bit (i, keypad->disabled_gpios)) { - gpio = pdata->row_gpios[i]; - -if (enable_irq_wake (gpio_to_irq (gpio)) ==0 ) +for (i =0 ; i < pdata->num_row_gpios; i++) +if (!test_bit (i, keypad->disabled_gpios)) +if (enable_irq_wake (keypad->row_irqs[i]) ==0 )__set_bit (i, keypad->disabled_gpios); - } - } } }static void matrix_keypad_disable_wakeup (struct matrix_keypad *keypad) {const struct matrix_keypad_platform_data *pdata = keypad->pdata; -unsigned int gpio;int i;if (pdata->clustered_irq >0 ) {
@@ -264,12 +259,9 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) keypad->gpio_all_disabled = false; } }else { -for (i =0 ; i < pdata->num_row_gpios; i++) { -if (test_and_clear_bit (i, keypad->disabled_gpios)) { - gpio = pdata->row_gpios[i]; -disable_irq_wake (gpio_to_irq (gpio)); - } - } +for (i =0 ; i < pdata->num_row_gpios; i++) +if (test_and_clear_bit (i, keypad->disabled_gpios)) +disable_irq_wake (keypad->row_irqs[i]); } }
@@ -306,7 +298,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, struct matrix_keypad *keypad) {const struct matrix_keypad_platform_data *pdata = keypad->pdata; -int i, err; +int i, irq, err;/* initialized strobe lines as outputs, activated */ for (i =0 ; i < pdata->num_col_gpios; i++) {
@@ -345,11 +337,19 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, } }else {for (i =0 ; i < pdata->num_row_gpios; i++) { - err =request_any_context_irq ( -gpio_to_irq (pdata->row_gpios[i]), + irq =gpio_to_irq (pdata->row_gpios[i]); +if (irq <0 ) { + err = irq; +dev_err (&pdev->dev, +"Unable to convert GPIO line %i to irq: %d\n" , + pdata->row_gpios[i], err); + goto err_free_irqs; + } + + err =request_any_context_irq (irq, matrix_keypad_interrupt,IRQF_TRIGGER_RISING | -IRQF_TRIGGER_FALLING , +IRQF_TRIGGER_FALLING ,"matrix-keypad" , keypad);if (err <0 ) { dev_err(&pdev->dev,
@@ -357,6 +357,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, pdata->row_gpios[i]); goto err_free_irqs; } + + keypad->row_irqs[i] = irq; } }
@@ -366,7 +368,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, err_free_irqs:while (--i >=0 ) -free_irq (gpio_to_irq (pdata->row_gpios[i]), keypad); +free_irq (keypad->row_irqs[i], keypad); i = pdata->num_row_gpios; err_free_rows:while (--i >=0 )
@@ -388,7 +390,7 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad)free_irq (pdata->clustered_irq, keypad); }else {for (i =0 ; i < pdata->num_row_gpios; i++) -free_irq (gpio_to_irq (pdata->row_gpios[i]), keypad); +free_irq (keypad->row_irqs[i], keypad); }for (i =0 ; i < pdata->num_row_gpios; i++)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1775/3318 Input: matrix_keypad - consolidate handling of clustered interrupt
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 8cf4b3683a713a4b54d44565e8a32b4cca357084 ]
Now that the driver stores interrupt numbers corresponding to individual GPIOs in non-clustered mode, it is possible to unify handling of both modes by storing clustered interrupt at position 0 and setting the number of interrupts in this case to 1.
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
--- drivers/input/keyboard/matrix_keypad.c | 63 ++++++++------------------ 1 file changed, 20 insertions(+), 43 deletions(-)
drivers/input/keyboard/matrix_keypad.c +20 -43
@@ -27,9 +27,10 @@ struct matrix_keypad {const struct matrix_keypad_platform_data *pdata;struct input_dev *input_dev;unsigned int row_shift; -unsigned int row_irqs[MATRIX_MAX_ROWS ]; -DECLARE_BITMAP (disabled_gpios,MATRIX_MAX_ROWS ); +unsigned int row_irqs[MATRIX_MAX_ROWS ]; +unsigned int num_row_irqs; +DECLARE_BITMAP (wakeup_enabled_irqs,MATRIX_MAX_ROWS );uint32_t last_key_state[MATRIX_MAX_COLS ];struct delayed_work work;
@@ -86,28 +87,18 @@ static bool row_asserted(const struct matrix_keypad_platform_data *pdata,static void enable_row_irqs (struct matrix_keypad *keypad) { -const struct matrix_keypad_platform_data *pdata = keypad->pdata;int i; -if (pdata->clustered_irq >0 ) -enable_irq (pdata->clustered_irq); -else { -for (i =0 ; i < pdata->num_row_gpios; i++) -enable_irq (keypad->row_irqs[i]); - } +for (i =0 ; i < keypad->num_row_irqs; i++) +enable_irq (keypad->row_irqs[i]); }static void disable_row_irqs (struct matrix_keypad *keypad) { -const struct matrix_keypad_platform_data *pdata = keypad->pdata;int i; -if (pdata->clustered_irq >0 ) -disable_irq_nosync (pdata->clustered_irq); -else { -for (i =0 ; i < pdata->num_row_gpios; i++) -disable_irq_nosync (keypad->row_irqs[i]); - } +for (i =0 ; i < keypad->num_row_irqs; i++) +disable_irq_nosync (keypad->row_irqs[i]); }/*
@@ -233,35 +224,20 @@ static void matrix_keypad_stop(struct input_dev *dev)static void matrix_keypad_enable_wakeup (struct matrix_keypad *keypad) { -const struct matrix_keypad_platform_data *pdata = keypad->pdata;int i; -if (pdata->clustered_irq >0 ) { -if (enable_irq_wake (pdata->clustered_irq) ==0 ) - keypad->gpio_all_disabled = true; - }else { - -for (i =0 ; i < pdata->num_row_gpios; i++) -if (!test_bit (i, keypad->disabled_gpios)) -if (enable_irq_wake (keypad->row_irqs[i]) ==0 ) -__set_bit (i, keypad->disabled_gpios); - } +for_each_clear_bit (i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) +if (enable_irq_wake (keypad->row_irqs[i]) ==0 ) +__set_bit (i, keypad->wakeup_enabled_irqs); }static void matrix_keypad_disable_wakeup (struct matrix_keypad *keypad) { -const struct matrix_keypad_platform_data *pdata = keypad->pdata;int i; -if (pdata->clustered_irq >0 ) { -if (keypad->gpio_all_disabled) { -disable_irq_wake (pdata->clustered_irq); - keypad->gpio_all_disabled = false; - } - }else { -for (i =0 ; i < pdata->num_row_gpios; i++) -if (test_and_clear_bit (i, keypad->disabled_gpios)) -disable_irq_wake (keypad->row_irqs[i]); +for_each_set_bit (i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) { +disable_irq_wake (keypad->row_irqs[i]); +__clear_bit (i, keypad->wakeup_enabled_irqs); } }
@@ -335,6 +311,9 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, "Unable to acquire clustered interrupt\n"); goto err_free_rows; } + + keypad->row_irqs[0 ] = pdata->clustered_irq; + keypad->num_row_irqs =1 ; }else {for (i =0 ; i < pdata->num_row_gpios; i++) { irq =gpio_to_irq (pdata->row_gpios[i]);
@@ -360,6 +339,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, keypad->row_irqs[i] = irq; } + + keypad->num_row_irqs = pdata->num_row_gpios; }/* initialized as disabled - enabled by input->open */
@@ -386,12 +367,8 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad)const struct matrix_keypad_platform_data *pdata = keypad->pdata;int i; -if (pdata->clustered_irq >0 ) { -free_irq (pdata->clustered_irq, keypad); - }else { -for (i =0 ; i < pdata->num_row_gpios; i++) -free_irq (keypad->row_irqs[i], keypad); - } +for (i =0 ; i < keypad->num_row_irqs; i++) +free_irq (keypad->row_irqs[i], keypad);for (i =0 ; i < pdata->num_row_gpios; i++)gpio_free (pdata->row_gpios[i]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1776/3318 Input: matrix_keypad - switch to using managed resources
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 7d0f351da46098b3bbb147f886f059473b84ff48 ]
Switch the drivers to use managed resources (devm) to simplify error handling and remove the need to have remove() implementation.
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
--- drivers/input/keyboard/matrix_keypad.c | 89 +++++++------------------- 1 file changed, 24 insertions(+), 65 deletions(-)
drivers/input/keyboard/matrix_keypad.c +24 -65
@@ -278,38 +278,41 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,/* initialized strobe lines as outputs, activated */ for (i =0 ; i < pdata->num_col_gpios; i++) { - err =gpio_request (pdata->col_gpios[i],"matrix_kbd_col" ); + err =devm_gpio_request (&pdev->dev, + pdata->col_gpios[i],"matrix_kbd_col" );if (err) {dev_err (&pdev->dev,"failed to request GPIO%d for COL%d\n" , pdata->col_gpios[i], i); - goto err_free_cols; +return err; }gpio_direction_output (pdata->col_gpios[i], !pdata->active_low); }for (i =0 ; i < pdata->num_row_gpios; i++) { - err =gpio_request (pdata->row_gpios[i],"matrix_kbd_row" ); + err =devm_gpio_request (&pdev->dev, + pdata->row_gpios[i],"matrix_kbd_row" );if (err) {dev_err (&pdev->dev,"failed to request GPIO%d for ROW%d\n" , pdata->row_gpios[i], i); - goto err_free_rows; +return err; }gpio_direction_input (pdata->row_gpios[i]); }if (pdata->clustered_irq >0 ) { - err =request_any_context_irq (pdata->clustered_irq, + err =devm_request_any_context_irq (&pdev->dev, + pdata->clustered_irq, matrix_keypad_interrupt, pdata->clustered_irq_flags,"matrix-keypad" , keypad);if (err <0 ) {dev_err (&pdev->dev,"Unable to acquire clustered interrupt\n" ); - goto err_free_rows; +return err; } keypad->row_irqs[0 ] = pdata->clustered_irq;
@@ -322,10 +325,11 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,dev_err (&pdev->dev,"Unable to convert GPIO line %i to irq: %d\n" , pdata->row_gpios[i], err); - goto err_free_irqs; +return err; } - err = request_any_context_irq(irq, + err = devm_request_any_context_irq(&pdev->dev, + irq, matrix_keypad_interrupt, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
@@ -334,7 +338,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,dev_err (&pdev->dev,"Unable to acquire interrupt for GPIO line %i\n" , pdata->row_gpios[i]); - goto err_free_irqs; +return err; } keypad->row_irqs[i] = irq;
@@ -345,36 +349,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,/* initialized as disabled - enabled by input->open */ disable_row_irqs (keypad); -return 0 ; - -err_free_irqs: -while (--i >=0 ) -free_irq (keypad->row_irqs[i], keypad); - i = pdata->num_row_gpios; -err_free_rows: -while (--i >=0 ) -gpio_free (pdata->row_gpios[i]); - i = pdata->num_col_gpios; -err_free_cols: -while (--i >=0 ) -gpio_free (pdata->col_gpios[i]); - -return err; -} - -static void matrix_keypad_free_gpio (struct matrix_keypad *keypad) -{ -const struct matrix_keypad_platform_data *pdata = keypad->pdata; -int i; - -for (i =0 ; i < keypad->num_row_irqs; i++) -free_irq (keypad->row_irqs[i], keypad); - -for (i =0 ; i < pdata->num_row_gpios; i++) -gpio_free (pdata->row_gpios[i]); -for (i =0 ; i < pdata->num_col_gpios; i++) -gpio_free (pdata->col_gpios[i]); +return 0 ; }#ifdef CONFIG_OF
@@ -473,12 +449,13 @@ static int matrix_keypad_probe(struct platform_device *pdev)return -EINVAL ; } - keypad =kzalloc (sizeof (struct matrix_keypad ),GFP_KERNEL ); - input_dev =input_allocate_device (); -if (!keypad || !input_dev) { - err = -ENOMEM ; - goto err_free_mem; - } + keypad =devm_kzalloc (&pdev->dev,sizeof (*keypad),GFP_KERNEL ); +if (!keypad) +return -ENOMEM ; + + input_dev =devm_input_allocate_device (&pdev->dev); +if (!input_dev) +return -ENOMEM ; keypad->input_dev = input_dev; keypad->pdata = pdata;
@@ -489,7 +466,6 @@ static int matrix_keypad_probe(struct platform_device *pdev) input_dev->name = pdev->name; input_dev->id.bustype =BUS_HOST ; - input_dev->dev.parent = &pdev->dev; input_dev->open = matrix_keypad_start; input_dev->close = matrix_keypad_stop;
@@ -499,7 +475,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) NULL, input_dev);if (err) {dev_err (&pdev->dev,"failed to build keymap\n" ); - goto err_free_mem; +return -ENOMEM ; }if (!pdata->no_autorepeat)
@@ -509,32 +485,16 @@ static int matrix_keypad_probe(struct platform_device *pdev) err =matrix_keypad_init_gpio (pdev, keypad);if (err) - goto err_free_mem; +return err; err =input_register_device (keypad->input_dev);if (err) - goto err_free_gpio; +return err;device_init_wakeup (&pdev->dev, pdata->wakeup);platform_set_drvdata (pdev, keypad);return 0 ; - -err_free_gpio: -matrix_keypad_free_gpio (keypad); -err_free_mem: -input_free_device (input_dev); -kfree (keypad); -return err; -} - -static void matrix_keypad_remove (struct platform_device *pdev) -{ -struct matrix_keypad *keypad =platform_get_drvdata (pdev); - -matrix_keypad_free_gpio (keypad); -input_unregister_device (keypad->input_dev); -kfree (keypad); }#ifdef CONFIG_OF
@@ -547,7 +507,6 @@ MODULE_DEVICE_TABLE(of, matrix_keypad_dt_match);static struct platform_driver matrix_keypad_driver = { .probe = matrix_keypad_probe, - .remove_new = matrix_keypad_remove, .driver = { .name ="matrix-keypad" , .pm =pm_sleep_ptr (&matrix_keypad_pm_ops),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1777/3318 Input: matrix_keypad - remove support for clustered interrupt
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
[ Upstream commit 5080f62adb126e28d316298505272efea0aed81a ]
There are no users of this functionality in the mainline kernel (it was only available to boards using platform data and not device tree). Remove it to simplify the code.
Stable-dep-of: 1527451f87df ("Revert "Input: matrix_keypad - force switch rows to input mode"")
--- drivers/input/keyboard/matrix_keypad.c | 61 ++++++++++---------------- 1 file changed, 22 insertions(+), 39 deletions(-)
drivers/input/keyboard/matrix_keypad.c +22 -39
@@ -29,7 +29,6 @@ struct matrix_keypad {unsigned int row_shift;unsigned int row_irqs[MATRIX_MAX_ROWS ]; -unsigned int num_row_irqs;DECLARE_BITMAP (wakeup_enabled_irqs,MATRIX_MAX_ROWS );uint32_t last_key_state[MATRIX_MAX_COLS ];
@@ -89,7 +88,7 @@ static void enable_row_irqs(struct matrix_keypad *keypad) {int i; -for (i =0 ; i < keypad->num_row_irqs; i++) +for (i =0 ; i < keypad->pdata->num_row_gpios; i++)enable_irq (keypad->row_irqs[i]); }
@@ -97,7 +96,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad) {int i; -for (i =0 ; i < keypad->num_row_irqs; i++) +for (i =0 ; i < keypad->pdata->num_row_gpios; i++)disable_irq_nosync (keypad->row_irqs[i]); }
@@ -226,7 +225,8 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) {int i; -for_each_clear_bit (i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) +for_each_clear_bit (i, keypad->wakeup_enabled_irqs, + keypad->pdata->num_row_gpios)if (enable_irq_wake (keypad->row_irqs[i]) ==0 )__set_bit (i, keypad->wakeup_enabled_irqs); }
@@ -235,7 +235,8 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) {int i; -for_each_set_bit (i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) { +for_each_set_bit (i, keypad->wakeup_enabled_irqs, + keypad->pdata->num_row_gpios) {disable_irq_wake (keypad->row_irqs[i]);__clear_bit (i, keypad->wakeup_enabled_irqs); }
@@ -303,48 +304,30 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,gpio_direction_input (pdata->row_gpios[i]); } -if (pdata->clustered_irq >0 ) { +for (i =0 ; i < pdata->num_row_gpios; i++) { + irq =gpio_to_irq (pdata->row_gpios[i]); +if (irq <0 ) { + err = irq; +dev_err (&pdev->dev, +"Unable to convert GPIO line %i to irq: %d\n" , + pdata->row_gpios[i], err); +return err; + } + err =devm_request_any_context_irq (&pdev->dev, - pdata->clustered_irq, + irq, matrix_keypad_interrupt, - pdata->clustered_irq_flags, +IRQF_TRIGGER_RISING | +IRQF_TRIGGER_FALLING ,"matrix-keypad" , keypad);if (err <0 ) {dev_err (&pdev->dev, -"Unable to acquire clustered interrupt\n" ); +"Unable to acquire interrupt for GPIO line %i\n" , + pdata->row_gpios[i]);return err; } - keypad->row_irqs[0 ] = pdata->clustered_irq; - keypad->num_row_irqs =1 ; - }else { -for (i =0 ; i < pdata->num_row_gpios; i++) { - irq =gpio_to_irq (pdata->row_gpios[i]); -if (irq <0 ) { - err = irq; -dev_err (&pdev->dev, -"Unable to convert GPIO line %i to irq: %d\n" , - pdata->row_gpios[i], err); -return err; - } - - err =devm_request_any_context_irq (&pdev->dev, - irq, - matrix_keypad_interrupt, -IRQF_TRIGGER_RISING | -IRQF_TRIGGER_FALLING , -"matrix-keypad" , keypad); -if (err <0 ) { -dev_err (&pdev->dev, -"Unable to acquire interrupt for GPIO line %i\n" , - pdata->row_gpios[i]); -return err; - } - - keypad->row_irqs[i] = irq; - } - - keypad->num_row_irqs = pdata->num_row_gpios; + keypad->row_irqs[i] = irq; }/* initialized as disabled - enabled by input->open */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1778/3318 Revert "Input: matrix_keypad - force switch rows to input mode"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Kochetkov <[email protected]>
[ Upstream commit 1527451f87dfe368b8ddeeb501c24ac9bde6b589 ]
This reverts commit 01c84b03d80aab9f04c4e3e1f9085f4202ff7c29.
The commit makes every scan call gpiod_direction_input() on the row GPIOs. On pin controllers where GPIO input and interrupt are separate pinmux functions this switches the row pins out of interrupt mode, and enable_row_irqs() does not switch them back: it only unmasks the interrupts. Row interrupts then never arrive and the keypad stops working. Seen with a matrix keypad on an Allwinner A64 board (PINE A64-LTS); it works again with the commit reverted.
The workaround is not needed on Ingenic either: the author of the reverted commit re-tested all available JZ47xx SoCs and they all report the live pin state in interrupt mode, see the thread in Link.
--- drivers/input/keyboard/matrix_keypad.c | 3 --- 1 file changed, 3 deletions(-)
drivers/input/keyboard/matrix_keypad.c +0 -3
@@ -118,9 +118,6 @@ static void matrix_keypad_scan(struct work_struct *work)memset (new_state,0 ,sizeof (new_state)); -for (row =0 ; row < pdata->num_row_gpios; row++) -gpio_direction_input (pdata->row_gpios[row]); -/* assert each column and read the row status out */ for (col =0 ; col < pdata->num_col_gpios; col++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1779/3318 tpm: tpm2_probe: propagate transport errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Sverdlin <[email protected]>
[ Upstream commit 7d4f1cbfe063af5581dac66abe9e9c965e1031cc ]
tpm2_probe() reads the protocol version from the response tag and is documented to return -errno on failure, but it always returns 0. A transport error (tpm_transmit_cmd() < 0) is thus swallowed together with the intentionally ignored TPM response code, leaving TPM_CHIP_FLAG_TPM2 unset. A transient bus failure on the first command then misdetects a TPM 2.0 as a 1.2 and the probe fails on the TPM 1.2 path:
tpm_tis_i2c 0-002e: 1.2 TPM (device-id 0x1C, rev-id 22)
tpm tpm0: A TPM error (-62) occurred attempting to determine the timeouts
Return the transport error instead; rc >= 0 still means a valid header was received and the TPM's own response code is still ignored.
--- drivers/char/tpm/tpm2-cmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm2-cmd.c +2 -1
@@ -507,9 +507,10 @@ int tpm2_probe(struct tpm_chip *chip) out = (struct tpm_header *)buf.data;if (be16_to_cpu (out->tag) ==TPM2_ST_NO_SESSIONS ) chip->flags |=TPM_CHIP_FLAG_TPM2 ; + rc =0 ; }tpm_buf_destroy (&buf); -return 0 ; +return rc; }EXPORT_SYMBOL_GPL (tpm2_probe);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1780/3318 gpio: pca953x: Utilise temporary variable for struct gpio_chip
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 9da0a75ea7ced4731b1f2c6c67dc409e40efb95a ]
We have a temporary variable to keep pointer to struct gpio_chip. Utilise it where it makes sense.
Stable-dep-of: a0fe26929350 ("gpio: pca953x: Handle direction register read errors in IRQ paths")
--- drivers/gpio/gpio-pca953x.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpio/gpio-pca953x.c +3 -4
@@ -690,9 +690,7 @@ static int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset,static void pca953x_setup_gpio (struct pca953x_chip *chip,int gpios) { -struct gpio_chip *gc; - - gc = &chip->gpio_chip; +struct gpio_chip *gc = &chip->gpio_chip; gc->direction_input = pca953x_gpio_direction_input; gc->direction_output = pca953x_gpio_direction_output;
@@ -958,6 +956,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)struct device *dev = &client->dev;DECLARE_BITMAP (reg_direction,MAX_LINE );DECLARE_BITMAP (irq_stat,MAX_LINE ); +struct gpio_chip *gc = &chip->gpio_chip;struct gpio_irq_chip *girq;int ret;
@@ -986,7 +985,7 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)* this purpose. */ pca953x_read_regs (chip, chip->regs->direction, reg_direction); -bitmap_and (chip->irq_stat, irq_stat, reg_direction, chip->gpio_chip.ngpio); +bitmap_and (chip->irq_stat, irq_stat, reg_direction, gc->ngpio);mutex_init (&chip->irq_lock); girq = &chip->gpio_chip.irq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1781/3318 gpio: pca953x: Handle direction register read errors in IRQ paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sahaj Chaudhari <[email protected]>
[ Upstream commit a0fe269293509acdd93b9cfb3f46636f7b91b33a ]
Three IRQ paths ignore the result of reading the direction registers and then use the destination bitmap. pca953x_read_regs() does not populate that bitmap when regmap_bulk_read() fails, leaving the callers to use uninitialized stack data.
This can select incorrect GPIOs for direction changes during IRQ bus synchronization, corrupt the saved input state during IRQ setup, or produce incorrect pending interrupt decisions.
Check the read result at all three sites. Release irq_lock without changing GPIO directions on failure, leave the IRQ history untouched when pending detection fails, and propagate the error from IRQ setup. The read helper already logs the error.
--- drivers/gpio/gpio-pca953x.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/gpio/gpio-pca953x.c +11 -3
@@ -763,6 +763,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)DECLARE_BITMAP (irq_mask,MAX_LINE );DECLARE_BITMAP (reg_direction,MAX_LINE );int level; +int ret;guard (mutex)(&chip->i2c_lock);
@@ -777,7 +778,9 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) }/* Switch direction to input if needed */ -pca953x_read_regs (chip, chip->regs->direction, reg_direction); + ret =pca953x_read_regs (chip, chip->regs->direction, reg_direction); +if (ret) + goto out;bitmap_or (irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio);bitmap_or (irq_mask, irq_mask, chip->irq_trig_level_high, gc->ngpio);
@@ -789,6 +792,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)for_each_set_bit (level, irq_mask, gc->ngpio)pca953x_gpio_direction_input_unlocked (&chip->gpio_chip, level); +out:mutex_unlock (&chip->irq_lock); }
@@ -883,7 +887,9 @@ static bool pca953x_irq_pending(struct pca953x_chip *chip, unsigned long *pendin }/* Remove output pins from the equation */ -pca953x_read_regs (chip, chip->regs->direction, reg_direction); + ret =pca953x_read_regs (chip, chip->regs->direction, reg_direction); +if (ret) +return false;bitmap_copy (old_stat, chip->irq_stat, gc->ngpio);
@@ -984,7 +990,9 @@ static int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base)* interrupt. We have to rely on the previous read for * this purpose. */ -pca953x_read_regs (chip, chip->regs->direction, reg_direction); + ret =pca953x_read_regs (chip, chip->regs->direction, reg_direction); +if (ret) +return ret;bitmap_and (chip->irq_stat, irq_stat, reg_direction, gc->ngpio);mutex_init (&chip->irq_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1782/3318 power: supply: bq27xxx: Ensure poll work is cancelled on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit db560f4b1c5253853f978385db066220e0c218dc ]
The di->work poll work is queued from the poll callback itself and from bq27xxx_external_power_changed(). The cancel_delayed_work_sync() in bq27xxx_battery_teardown() runs while the power_supply is still registered, so external_power_changed() can re-arm the work after the cancel, and it runs after the driver data has been freed.
Register a devm_delayed_work_autocancel() before devm_power_supply_register(), so on unwind the power_supply is unregistered first, after which no new external_power_changed() callback can be dispatched, and the poll work is cancelled only then. Drop the now-redundant cancel from bq27xxx_battery_teardown().
This issue was found by an in-house static analysis tool.
--- drivers/power/supply/bq27xxx_battery.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/power/supply/bq27xxx_battery.c +11 -5
@@ -43,6 +43,7 @@*/ #include <linux/device.h> +#include <linux/devm-helpers.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/param.h>
@@ -2141,9 +2142,11 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) .of_node = di->dev->of_node, .drv_data = di, }; +int ret; -INIT_DELAYED_WORK (&di->work, bq27xxx_battery_poll); -mutex_init (&di->lock); + ret =devm_mutex_init (di->dev, &di->lock); +if (ret) +return ret; di->regs = bq27xxx_chip_data[di->chip].regs; di->unseal_key = bq27xxx_chip_data[di->chip].unseal_key;
@@ -2161,6 +2164,12 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) psy_desc->get_property = bq27xxx_battery_get_property; psy_desc->external_power_changed = bq27xxx_external_power_changed; +/* Cancel the poll work after the power_supply is unregistered. */ + ret =devm_delayed_work_autocancel (di->dev, &di->work, + bq27xxx_battery_poll); +if (ret) +return ret; + di->bat =power_supply_register_no_ws (di->dev, psy_desc, &psy_cfg);if (IS_ERR (di->bat)) return dev_err_probe(di->dev, PTR_ERR(di->bat),
@@ -2188,10 +2197,7 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di) di->removed = true;mutex_unlock (&di->lock); -cancel_delayed_work_sync (&di->work); -power_supply_unregister (di->bat); -mutex_destroy (&di->lock); }EXPORT_SYMBOL_GPL (bq27xxx_battery_teardown);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1783/3318 fs: rotate inodes whose page cache could not be dropped
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolaos Karaolidis <[email protected]>
[ Upstream commit 8ee09f597763acfd31c62a578ba88b792fc41b24 ]
When inode_lru_isolate() drops the page cache of an unused inode, it has to unlock the list, so it returns LRU_RETRY and the walk restarts at the head of the list, where the inode still is. If invalidate_mapping_pages() could not empty the mapping, the restarted walk strips the same inode again, and so on until nr_to_walk runs out. Every walk of that list then ends on this inode, and nothing behind it is reclaimed for as long as its cache stays.
Before commit 2a0629834cd8 ("vfs: Don't evict inode under the inode lru traversing context") the walker pinned the inode with a reference, and dropping it in iput_final() set I_REFERENCED, so the restarted walk rotated the inode to the tail. Set I_REFERENCED again when the mapping is still populated after the invalidation, in the same i_lock section that clears I_LRU_ISOLATING. inode_unpin_lru_isolating() now expects i_lock to be held, like inode_pin_lru_isolating().
On CONFIG_HIGHMEM kernels this can happen to any unused inode: a folio is left behind if it is locked, under writeback, spliced into a pipe, or still in another CPU's LRU-add batch after being read. Without HIGHMEM it happens to DAX inodes whose only entry is at index 0, which mapping_shrinkable() lets onto the LRU and invalidate_mapping_pages() never removes.
--- fs/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/inode.c +7 -2
@@ -495,12 +495,11 @@ static void inode_pin_lru_isolating(struct inode *inode)static void inode_unpin_lru_isolating (struct inode *inode) { -spin_lock (&inode->i_lock); +lockdep_assert_held (&inode->i_lock);WARN_ON (!(inode->i_state &I_LRU_ISOLATING )); inode->i_state &= ~I_LRU_ISOLATING ;smp_mb ();wake_up_bit (&inode->i_state, __I_LRU_ISOLATING); -spin_unlock (&inode->i_lock); }static void inode_wait_for_lru_isolating (struct inode *inode)
@@ -894,7 +893,13 @@ static enum lru_status inode_lru_isolate(struct list_head *item,__count_vm_events (PGINODESTEAL , reap);mm_account_reclaimed_pages (reap); } + +spin_lock (&inode->i_lock); +/* The walk restarts here: don't retry leftovers right away */ +if (!mapping_empty (&inode->i_data)) + inode->i_state |=I_REFERENCED ;inode_unpin_lru_isolating (inode); +spin_unlock (&inode->i_lock);spin_lock (lru_lock);return LRU_RETRY ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1784/3318 arm64: dts: freescale: imx8mp-verdin-yavia: fix external GPIOs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Dolcini <[email protected]>
[ Upstream commit f377ac5999a5d045168ddd25d204691c6653c06a ]
pinctrl_gpios_ext_yavia (SODIMM 64/66) is defined but never applied to gpio3, so those pins stay at their NAND reset function instead of GPIO.
Fix SODIMM 64 to the correct pad, MX8MP_IOMUXC_NAND_READY_B (GPIO3_IO16).
--- arch/arm64/boot/dts/freescale/imx8mp-verdin-yavia.dtsi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/freescale/imx8mp-verdin-yavia.dtsi +6 -1
@@ -100,6 +100,11 @@ &flexcan1 { status = "okay"; }; +&gpio3 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_gpios_ext_yavia>; +}; + &hwmon_temp { status = "okay"; };
@@ -205,7 +210,7 @@ MX8MP_IOMUXC_NAND_DATA03__GPIO3_IO09 0x106 /* SODIMM 62 */ pinctrl_gpios_ext_yavia: gpiosextyaviagrp { fsl,pins = < - MX8MP_IOMUXC_NAND_CE1_B__GPIO3_IO02 0x106 /* SODIMM 64 */ + MX8MP_IOMUXC_NAND_READY_B__GPIO3_IO16 0x106 /* SODIMM 64 */ MX8MP_IOMUXC_NAND_DQS__GPIO3_IO14 0x106 /* SODIMM 66 */ >; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1785/3318 amdkfd: Fix memory availability double accounting of kfd pinned objects
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Phillips <[email protected]>
[ Upstream commit 16df12d7158fb55f20d6e985abd1996cbabab9f8 ]
Pinned objects that are not kfd objects reduce the total vram available to kfd, so we subtract the total size of pinned objects from kdf vram availability. However this double counts objects pinned by kfd itself, because they are counted both as used and pinned. So track the total size of objects pinned by kfd and add it back to kfd availability to remove the double accounting.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -100,6 +100,7 @@ struct amdgpu_kfd_dev {struct kfd_dev *dev;int64_t vram_used[MAX_XCP ];uint64_t vram_used_aligned[MAX_XCP ]; +atomic64_t vram_pinned;bool init_complete;struct work_struct reset_work;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +11 -0
@@ -1432,6 +1432,11 @@ static int amdgpu_amdkfd_gpuvm_pin_bo(struct amdgpu_bo *bo, u32 domain)pr_err ("Error in Pinning BO to domain: %d\n" , domain);amdgpu_bo_sync_wait (bo,AMDGPU_FENCE_OWNER_KFD , false); + +if (!ret && bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_add (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); +amdgpu_bo_unreserve (bo);return ret;
@@ -1454,6 +1459,11 @@ static void amdgpu_amdkfd_gpuvm_unpin_bo(struct amdgpu_bo *bo)return ;amdgpu_bo_unpin (bo); + +if (bo->tbo.resource->mem_type ==TTM_PL_VRAM ) +atomic64_sub (amdgpu_bo_size (bo), + &amdgpu_ttm_adev (bo->tbo.bdev)->kfd.vram_pinned); +amdgpu_bo_unreserve (bo); }
@@ -1610,6 +1620,7 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev, vram_available =KFD_XCP_MEMORY_SIZE (adev, xcp_id) - adev->kfd.vram_used_aligned[xcp_id] -atomic64_read (&adev->vram_pin_size) + +atomic64_read (&adev->kfd.vram_pinned) - reserved_for_pt;if (adev->gmc.is_app_apu) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1786/3318 fuse: dont drop destination page cache on a zero byte copy reply
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Koong <[email protected]>
[ Upstream commit f7585e1ce3418ec282485854b3d8d31c6a961e37 ]
__fuse_copy_file_range() clears the destination page cache after the server replies:
truncate_inode_pages_range(inode_out->i_mapping, ALIGN_DOWN(pos_out, PAGE_SIZE), ALIGN(pos_out + bytes_copied, PAGE_SIZE) - 1);
A server may legitimately reply that it copied nothing, eg if the source file turns out to be shorter than the size the kernel has cached for it.
If pos_out is 0 as well, the end of the range is ALIGN(0, PAGE_SIZE) - 1, which is -1. lend is a uoff_t and truncate_inode_pages_range() takes -1 as its end of file sentinel, so rather than clearing nothing it drops every folio in the destination mapping.
That is not only a cache drop. truncate_cleanup_folio() calls folio_cancel_dirty(), and fuse_writeback_range() only wrote back [pos_out, pos_out + len - 1], so dirty data elsewhere in the destination file is discarded without ever reaching the server.
Skip the call when the server copied nothing, since there is nothing stale to clear in that case.
--- fs/fuse/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/fuse/file.c +5 -3
@@ -3263,9 +3263,11 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,if (err) goto out; -truncate_inode_pages_range (inode_out->i_mapping, -ALIGN_DOWN (pos_out,PAGE_SIZE ), -ALIGN (pos_out + outarg.size,PAGE_SIZE ) -1 ); +if (outarg.size) +truncate_inode_pages_range (inode_out->i_mapping, +ALIGN_DOWN (pos_out,PAGE_SIZE ), +ALIGN (pos_out + outarg.size, +PAGE_SIZE ) -1 );file_update_time (file_out);fuse_write_update_attr (inode_out, pos_out + outarg.size, outarg.size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1787/3318 media: qcom: camss: Move vfe_disable into a common routine where applicable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan O'Donoghue <[email protected]>
[ Upstream commit 90cc4555730bfd0fc6af5c8a5a81d80bfce4cff7 ]
We can move vfe_disable() into a common routine in the core VFE file provided we make wm_stop() a VFE specific callback.
The callback is required to capture the case where VFE 17x currently isn't VC enabled where as VFE 480 is.
Stable-dep-of: e5d4b0e69a40 ("media: qcom: camss: vfe: Fix VFE reset while another line is streaming")
--- .../media/platform/qcom/camss/camss-vfe-170.c | 40 +------------------ .../media/platform/qcom/camss/camss-vfe-480.c | 40 +------------------ drivers/media/platform/qcom/camss/camss-vfe.c | 39 ++++++++++++++++++ drivers/media/platform/qcom/camss/camss-vfe.h | 9 +++++ 4 files changed, 50 insertions(+), 78 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe-170.c +1 -39
@@ -492,22 +492,6 @@ static int vfe_enable_output(struct vfe_line *line)return 0 ; } -static void vfe_disable_output (struct vfe_line *line) -{ -struct vfe_device *vfe =to_vfe (line); -struct vfe_output *output = &line->output; -unsigned long flags; -unsigned int i; - -spin_lock_irqsave (&vfe->output_lock, flags); -for (i =0 ; i < output->wm_num; i++) -vfe_wm_stop (vfe, output->wm_idx[i]); - output->gen2.active_num =0 ; -spin_unlock_irqrestore (&vfe->output_lock, flags); - -vfe_reset (vfe); -} -/* * vfe_enable - Enable streaming on VFE line * @line: VFE line
@@ -553,29 +537,6 @@ static int vfe_enable(struct vfe_line *line)return ret; } -/* -* vfe_disable - Disable streaming on VFE line -* @line: VFE line -* -* Return 0 on success or a negative error code otherwise -*/ -static int vfe_disable (struct vfe_line *line) -{ -struct vfe_device *vfe =to_vfe (line); - -vfe_disable_output (line); - -vfe_put_output (line); - -mutex_lock (&vfe->stream_lock); - - vfe->stream_count--; - -mutex_unlock (&vfe->stream_lock); - -return 0 ; -} -/* * vfe_isr_sof - Process start of frame interrupt * @vfe: VFE Device
@@ -770,4 +731,5 @@ const struct vfe_hw_ops vfe_ops_170 = { .vfe_enable = vfe_enable, .vfe_halt = vfe_halt, .violation_read = vfe_violation_read, + .vfe_wm_stop = vfe_wm_stop, };
drivers/media/platform/qcom/camss/camss-vfe-480.c +1 -39
@@ -329,22 +329,6 @@ static int vfe_enable_output(struct vfe_line *line)return 0 ; } -static void vfe_disable_output (struct vfe_line *line) -{ -struct vfe_device *vfe =to_vfe (line); -struct vfe_output *output = &line->output; -unsigned long flags; -unsigned int i; - -spin_lock_irqsave (&vfe->output_lock, flags); -for (i =0 ; i < output->wm_num; i++) -vfe_wm_stop (vfe, output->wm_idx[i]); - output->gen2.active_num =0 ; -spin_unlock_irqrestore (&vfe->output_lock, flags); - -vfe_reset (vfe); -} -/* * vfe_enable - Enable streaming on VFE line * @line: VFE line
@@ -392,29 +376,6 @@ static int vfe_enable(struct vfe_line *line)return ret; } -/* -* vfe_disable - Disable streaming on VFE line -* @line: VFE line -* -* Return 0 on success or a negative error code otherwise -*/ -static int vfe_disable (struct vfe_line *line) -{ -struct vfe_device *vfe =to_vfe (line); - -vfe_disable_output (line); - -vfe_put_output (line); - -mutex_lock (&vfe->stream_lock); - - vfe->stream_count--; - -mutex_unlock (&vfe->stream_lock); - -return 0 ; -} -/* * vfe_isr_reg_update - Process reg update interrupt * @vfe: VFE Device
@@ -584,4 +545,5 @@ const struct vfe_hw_ops vfe_ops_480 = { .vfe_disable = vfe_disable, .vfe_enable = vfe_enable, .vfe_halt = vfe_halt, + .vfe_wm_stop = vfe_wm_stop, };
drivers/media/platform/qcom/camss/camss-vfe.c +39 -0
@@ -407,6 +407,45 @@ int vfe_put_output(struct vfe_line *line)return 0 ; } +static int vfe_disable_output (struct vfe_line *line) +{ +struct vfe_device *vfe =to_vfe (line); +struct vfe_output *output = &line->output; +unsigned long flags; +unsigned int i; + +spin_lock_irqsave (&vfe->output_lock, flags); +for (i =0 ; i < output->wm_num; i++) + vfe->ops->vfe_wm_stop (vfe, output->wm_idx[i]); + output->gen2.active_num =0 ; +spin_unlock_irqrestore (&vfe->output_lock, flags); + +return vfe_reset (vfe); +} + +/* +* vfe_disable - Disable streaming on VFE line +* @line: VFE line +* +* Return 0 on success or a negative error code otherwise +*/ +int vfe_disable (struct vfe_line *line) +{ +struct vfe_device *vfe =to_vfe (line); + +vfe_disable_output (line); + +vfe_put_output (line); + +mutex_lock (&vfe->stream_lock); + + vfe->stream_count--; + +mutex_unlock (&vfe->stream_lock); + +return 0 ; +} +/** * vfe_isr_comp_done() - Process composite image done interrupt * @vfe: VFE Device
drivers/media/platform/qcom/camss/camss-vfe.h +9 -0
@@ -116,6 +116,7 @@ struct vfe_hw_ops {int (*vfe_enable)(struct vfe_line *line);int (*vfe_halt)(struct vfe_device *vfe);void (*violation_read)(struct vfe_device *vfe); +void (*vfe_wm_stop)(struct vfe_device *vfe,u8 wm); };struct vfe_isr_ops {
@@ -194,6 +195,14 @@ int vfe_reserve_wm(struct vfe_device *vfe, enum vfe_line_id line_id);*/ int vfe_reset (struct vfe_device *vfe); +/* +* vfe_disable - Disable streaming on VFE line +* @line: VFE line +* +* Return 0 on success or a negative error code otherwise +*/ +int vfe_disable (struct vfe_line *line); +extern const struct vfe_hw_ops vfe_ops_4_1;extern const struct vfe_hw_ops vfe_ops_4_7;extern const struct vfe_hw_ops vfe_ops_4_8;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1788/3318 media: qcom: camss: Propagate vfe_reset error up the callstack
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan O'Donoghue <[email protected]>
[ Upstream commit 5c07f30bed52ed85673b634f77467e404645785d ]
A previous patch I had removed the returns from vfe_disable() since we didn't trap any meaningful errors. Konrad pointed out vfe_reset() could return an error, which is true.
Trap the vfe_reset() error code and throw it up the callstack.
Stable-dep-of: e5d4b0e69a40 ("media: qcom: camss: vfe: Fix VFE reset while another line is streaming")
--- drivers/media/platform/qcom/camss/camss-vfe.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe.c +6 -2
@@ -432,8 +432,11 @@ static int vfe_disable_output(struct vfe_line *line)int vfe_disable (struct vfe_line *line) {struct vfe_device *vfe =to_vfe (line); +int ret; -vfe_disable_output (line); + ret =vfe_disable_output (line); +if (ret) + goto error;vfe_put_output (line);
@@ -443,7 +446,8 @@ int vfe_disable(struct vfe_line *line)mutex_unlock (&vfe->stream_lock); -return 0 ; +error: +return ret; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1789/3318 media: qcom: camss: vfe: Fix VFE reset while another line is streaming
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hitesh Patel <[email protected]>
[ Upstream commit e5d4b0e69a4017fd39354499c9d7583f625f0524 ]
vfe_disable_output() stops the write masters of the line being disabled and then resets the whole VFE. The reset is not limited to that line.
When two lines of one VFE stream at the same time, which is the case whenever a CSID demultiplexes several virtual channels to different RDIs, stopping the first line resets the VFE underneath the second line. The second line's write master configuration is wiped, the buffers it had in flight are never completed, and the VFE is left in a state in which the next global reset is not acknowledged. Stopping or restarting the second line then fails with:
VFE reset timeout
Move the reset to vfe_disable() and do it under stream_lock, as part of the decrement that makes the count reach zero, so that exactly one caller resets and no line can be enabled while the reset runs. Stopping the line's write masters is enough to quiesce that line on its own. With a single line streaming, the reset happens exactly as before.
--- drivers/media/platform/qcom/camss/camss-vfe.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe.c +5 -9
@@ -407,7 +407,7 @@ int vfe_put_output(struct vfe_line *line)return 0 ; } -static int vfe_disable_output (struct vfe_line *line) +static void vfe_disable_output (struct vfe_line *line) {struct vfe_device *vfe =to_vfe (line);struct vfe_output *output = &line->output;
@@ -419,8 +419,6 @@ static int vfe_disable_output(struct vfe_line *line) vfe->ops->vfe_wm_stop (vfe, output->wm_idx[i]); output->gen2.active_num =0 ;spin_unlock_irqrestore (&vfe->output_lock, flags); - -return vfe_reset (vfe); }/*
@@ -432,21 +430,19 @@ static int vfe_disable_output(struct vfe_line *line)int vfe_disable (struct vfe_line *line) {struct vfe_device *vfe =to_vfe (line); -int ret; +int ret =0 ; - ret =vfe_disable_output (line); -if (ret) - goto error; +vfe_disable_output (line);vfe_put_output (line);mutex_lock (&vfe->stream_lock); - vfe->stream_count--; +if (--vfe->stream_count ==0 ) + ret =vfe_reset (vfe);mutex_unlock (&vfe->stream_lock); -error:return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1790/3318 ASoC: hdac_hda: Allocate the private data at codec driver bind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 7d357eae973a1e1933f81f55aa1b3b4e3064570f ]
The SOF HDA code allocates struct hdac_hda_priv and stores it as drvdata of the codec device before the codec driver is bound. The driver core clears drvdata on unbind, so after unbinding the codec driver via sysfs a subsequent bind dereferences a NULL pointer in hdac_hda_dev_probe().
All information in the private data can be derived from the codec device itself, so allocate and set it up in hdac_hda_dev_probe() as a device managed resource, which is released on unbind.
Remove the allocation from SOF, keeping the check for iDisp codecs without display audio component.
Omit the dev_index initialization because the private structure has no such member and the firmware patch loader that uses it is absent. Keep the allocation tied to codec driver binding and preserve the existing iDisp audio-component check.
Stable-dep-of: 08a44bde821d ("ASoC: hdac_hda: Restore the codec device type on unbind")
--- sound/soc/codecs/hdac_hda.c | 12 +++++++++++- sound/soc/sof/intel/hda-codec.c | 22 ++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-)
sound/soc/codecs/hdac_hda.c +11 -1
@@ -606,10 +606,20 @@ static const struct snd_soc_component_driver hdac_hda_hdmi_codec = {static int hdac_hda_dev_probe (struct hdac_device *hdev) { -struct hdac_hda_priv *hda_pvt =dev_get_drvdata (&hdev->dev); +struct hdac_hda_priv *hda_pvt;struct hdac_ext_link *hlink;int ret; + hda_pvt =devm_kzalloc (&hdev->dev,sizeof (*hda_pvt),GFP_KERNEL ); +if (!hda_pvt) +return -ENOMEM ; + + hda_pvt->codec =dev_to_hda_codec (&hdev->dev); +/* Intel iDisp (HDMI/DP) codec */ +if (((hdev->vendor_id >>16 ) &0xFFFF ) ==0x8086 ) + hda_pvt->need_display_power = true; +dev_set_drvdata (&hdev->dev, hda_pvt); +/* hold the ref while we probe */ hlink =snd_hdac_ext_bus_get_hlink_by_name (hdev->bus,dev_name (&hdev->dev));if (!hlink) {
sound/soc/sof/intel/hda-codec.c +4 -18
@@ -15,8 +15,6 @@#include "hda.h" #if IS_ENABLED (CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC ) -#include "../../codecs/hdac_hda.h" -#define CODEC_PROBE_RETRIES 3#define IDISP_VID_INTEL 0x80860000
@@ -139,7 +137,6 @@ static struct hda_codec *hda_codec_device_init(struct hdac_bus *bus, int addr, i/* probe individual codec */ static int hda_codec_probe (struct snd_sof_dev *sdev,int address) { -struct hdac_hda_priv *hda_priv;struct hda_bus *hbus =sof_to_hbus (sdev);struct hda_codec *codec; u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) |
@@ -159,26 +156,15 @@ static int hda_codec_probe(struct snd_sof_dev *sdev, int address)dev_dbg (sdev->dev,"HDA codec #%d probed OK: response: %x\n" , address, resp); - hda_priv =devm_kzalloc (sdev->dev,sizeof (*hda_priv),GFP_KERNEL ); -if (!hda_priv) -return -ENOMEM ; - codec =hda_codec_device_init (&hbus->core, address,HDA_DEV_LEGACY ); ret =PTR_ERR_OR_ZERO (codec);if (ret <0 )return ret; - hda_priv->codec = codec; -dev_set_drvdata (&codec->core.dev, hda_priv); - -if ((resp &0xFFFF0000 ) ==IDISP_VID_INTEL ) { -if (!hbus->core.audio_component) { -dev_dbg (sdev->dev, -"iDisp hw present but no driver\n" ); - ret = -ENOENT ; - goto out; - } - hda_priv->need_display_power = true; +if ((resp &0xFFFF0000 ) ==IDISP_VID_INTEL && !hbus->core.audio_component) { +dev_dbg (sdev->dev,"iDisp hw present but no driver\n" ); + ret = -ENOENT ; + goto out; }if (is_generic_config (hbus))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1791/3318 ASoC: hdac_hda: Restore the codec device type on unbind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 08a44bde821d4fe22c0b6e63da04b3c59ac243a8 ]
hdac_hda_codec_probe() changes the type of the codec device to HDA_DEV_ASOC to prevent snd_hda_codec_unregister() from unregistering the device when the card is freed.
The type is never restored, and hda_bus_match() requires the device and driver types to be equal. After unbinding the codec driver via sysfs the HDA_DEV_LEGACY codec drivers no longer match the device and bind fails with -ENODEV.
Restore HDA_DEV_LEGACY with a device managed action registered before the component, so it runs after the component and the card are gone.
--- sound/soc/codecs/hdac_hda.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
sound/soc/codecs/hdac_hda.c +12 -0
@@ -604,6 +604,13 @@ static const struct snd_soc_component_driver hdac_hda_hdmi_codec = { .endianness = 1, }; +static void hdac_hda_restore_dev_type (void *data) +{ +struct hdac_device *hdev = data; + + hdev->type =HDA_DEV_LEGACY ; +} +static int hdac_hda_dev_probe (struct hdac_device *hdev) {struct hdac_hda_priv *hda_pvt;
@@ -620,6 +627,11 @@ static int hdac_hda_dev_probe(struct hdac_device *hdev) hda_pvt->need_display_power = true;dev_set_drvdata (&hdev->dev, hda_pvt); +/* Allow the legacy codec driver to match again after unbind */ + ret =devm_add_action (&hdev->dev, hdac_hda_restore_dev_type, hdev); +if (ret) +return ret; +/* hold the ref while we probe */ hlink =snd_hdac_ext_bus_get_hlink_by_name (hdev->bus,dev_name (&hdev->dev));if (!hlink) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1792/3318 mm/page_isolation: fix UBSAN shift-out-of-bounds warning
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qi Xi <[email protected]>
[ Upstream commit eba0e6297edd60a85bc96ff5cfb734d066af62dd ]
Patch series "mm/page_isolation: fix UBSAN shift-out-of-bounds in isolate_single_pageblock", v3.
Patch 1 fixes a UBSAN shift-out-of-bounds warning in the PageBuddy branch of isolate_single_pageblock() triggered by concurrent buddy allocation.
Patch 2 addresses the same class of issue in the PageCompound branch, where racy compound_order() and compound_head() reads could lead to out-of-range shifts or incorrect page skipping.
This patch (of 2):
A contig-range allocation racing with buddy allocation on the adjacent pageblock can trigger:
UBSAN: shift-out-of-bounds in mm/page_isolation.c:393:15 shift exponent -749042176 is negative Call trace: isolate_single_pageblock start_isolate_page_range alloc_contig_frozen_range_noprof alloc_contig_range_noprof
isolate_single_pageblock() first calls set_migratetype_isolate() with zone->lock held, which marks the pageblock MIGRATE_ISOLATE and moves any free page straddling the boundary out of the way. Once the lock is dropped, it scans the MAX_ORDER_NR_PAGES-aligned window [start_pfn, boundary_pfn) locklessly, only to skip the free pages already handled above and to detect in-use pages straddling the boundary. Since this scan only reads page state to decide how far to skip and returns -EBUSY on a straddling in-use page, it does not take the lock.
The window also covers the adjacent pageblock, whose free pages stay on the normal movable/CMA freelist and can be allocated concurrently. So after the scan observes PageBuddy(page), another CPU can allocate the page, leaving a stale value in page->private that makes "1 << order" shift out of range.
Use buddy_order_unsafe() with READ_ONCE to read the order, and validate it is within MAX_PAGE_ORDER before shifting to prevent UBSAN warnings.
Since pageblock_isolate_and_move_free_pages() already handles free pages straddling boundary_pfn under zone->lock, bail out with -EBUSY instead of VM_WARN_ON_ONCE() when a PageBuddy page appears to cross the boundary during the lockless scan.
--- mm/page_isolation.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/page_isolation.c +5 -1
@@ -372,7 +372,11 @@ static int isolate_single_pageblock(unsigned long boundary_pfn, int flags,* always be in the range. */ if (PageBuddy (page)) { -int order =buddy_order (page); +unsigned int order =buddy_order_unsafe (page); + +/* buddy_order_unsafe() is racy. Validate the order before shifting. */ +if (order >MAX_ORDER ) + goto failed;if (pfn + (1UL << order) > boundary_pfn) {/* free page changed before split, check it again */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1793/3318 fs: dont lose inodes that another LRU walker is isolating
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolaos Karaolidis <[email protected]>
[ Upstream commit 8dc4116041e2b377e5e1b62ba98b37636f9f3968 ]
When inode_lru_isolate() finds an unused inode that still has page cache, it sets I_LRU_ISOLATING, drops i_lock and the list_lru lock, invalidates the page cache, clears the flag again and returns LRU_RETRY so that the restarted walk can free the inode.
Another walker of the same list can reach the inode in that window. It sees a non-zero i_state and takes the inode off the LRU, as it would an inode that is in use. Page cache deletion requeues the inode once the mapping is shrinkable, so this is harmless if it happens before the last deletion. If it happens after, nothing puts the inode
back: it stays in memory, unused, clean and without page cache, out of reach of the shrinker and of drop_caches, until it is looked up again or the filesystem is unmounted.
Before commit 2a0629834cd8 ("vfs: Don't evict inode under the inode lru traversing context") the pin was an i_count reference, and the final iput() put the inode back on the LRU.
Skip inodes that are being isolated and leave them to the walker that pinned them, which restarts its walk once it has unpinned them.
The window is reached by any unused inode with page cache on CONFIG_HIGHMEM kernels, and otherwise by inodes whose page cache is a single shadow entry at index 0. On an i386 HIGHMEM guest, eight concurrent "echo 2 > /proc/sys/vm/drop_caches" over 2000 freshly read one-page ext4 files leave roughly 400 of the inodes off the LRU per round; on x86_64, with the files' pages first evicted through memory.reclaim, 3 to 4 per round. With this patch, none in either case.
--- fs/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/inode.c +6 -0
@@ -853,6 +853,12 @@ static enum lru_status inode_lru_isolate(struct list_head *item,if (!spin_trylock (&inode->i_lock))return LRU_SKIP ; +/* Another walker is dropping its page cache, leave it to that one */ +if (inode->i_state &I_LRU_ISOLATING ) { +spin_unlock (&inode->i_lock); +return LRU_SKIP ; + } +/* * Inodes can get referenced, redirtied, or repopulated while * they're already on the LRU, and this can make them
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1794/3318 LoongArch: Fix one-shot limitation for perf hardware breakpoints
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tiezhu Yang <[email protected]>
[ Upstream commit 5e0b00fd000a53a5428fed6c96be74019bd0ad17 ]
In breakpoint_handler() and watchpoint_handler(), the code disables the hardware slot by executing update_bp_registers(regs, 0, ...). This design forces the active hardware breakpoint configuration to be wiped out upon its first hit, turning standard perf hardware breakpoints into "one-shot" events.
Furthermore, while the ptrace single-step path in do_watch() executes a hardware single-step skip mechanism to advance the PC, the standard perf path lacks any mechanism to bypass the original triggering instruction.
To maintain the long-term persistence of hardware breakpoints for perf usage, eliminate the disruptive calls to update_bp_registers() within the handler loops to keep the breakpoint configuration enabled.
Concurrently, execute a single, unified register write outside the loop to atomize the state transition and explicitly enforce the hardware skip mechanism once per exception return, ensuring the processor safely steps forward without lockups.
Meanwhile, in order to prevent status contamination during single-core context switches or cross-core thread migrations, the hardware register skip state of the previous thread is saved first. Then, the skip state is restored and its software skip flag is also cleared only if the next thread has the skip flag; otherwise, 0 is written to clear the FWPS and MWPS registers, which explicitly clears the skip bit according to the architectural specification.
Additionally, explicitly clear hbp_break_skip and hbp_watch_skip inside ptrace_hw_copy_thread() which is called by copy_thread() during the task creation. This guarantees that a newly cloned child task starts with a clean slate.
Here is a user-space reproducer to demonstrate the issue.
(1) Test program (test_perf_continuous.c):
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/ioctl.h>
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
static int var = 0;
int main(void)
{
size_t count = 0;
struct perf_event_attr attr = {
.type = PERF_TYPE_BREAKPOINT,
.size = sizeof(attr),
.bp_type = HW_BREAKPOINT_W,
.bp_addr = (unsigned long)&var,
.bp_len = HW_BREAKPOINT_LEN_1,
.exclude_kernel = 1,
};
int fd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
asm volatile("st.b %1, %0" : "=m"(var) : "r"(11) : "memory");
asm volatile("st.b %1, %0" : "=m"(var) : "r"(22) : "memory");
asm volatile("st.b %1, %0" : "=m"(var) : "r"(33) : "memory");
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
read(fd, &count, sizeof(size_t));
printf("Watchpoint counts: expected = 3, actual = %zu\n", count);
close(fd);
return 0;
}(2) Test steps:
$ gcc test_perf_continuous.c -o test_perf_continuous $ ./test_perf_continuous
(3) Test results:
Without this patch:
Watchpoint counts: expected = 3, actual = 1
With this patch:
Watchpoint counts: expected = 3, actual = 3
--- arch/loongarch/include/asm/hw_breakpoint.h | 4 +-- arch/loongarch/include/asm/loongarch.h | 3 ++ arch/loongarch/include/asm/processor.h | 1 + arch/loongarch/include/asm/switch_to.h | 2 +- arch/loongarch/kernel/hw_breakpoint.c | 39 +++++++++++++++++++--- 5 files changed, 41 insertions(+), 8 deletions(-)
arch/loongarch/include/asm/hw_breakpoint.h +2 -2
@@ -121,12 +121,12 @@ bool watchpoint_handler(struct pt_regs *regs);#ifdef CONFIG_HAVE_HW_BREAKPOINT extern void ptrace_hw_copy_thread (struct task_struct *task); -extern void hw_breakpoint_thread_switch (struct task_struct *next); +extern void hw_breakpoint_thread_switch (struct task_struct *prev,struct task_struct *next);#else static inline void ptrace_hw_copy_thread (struct task_struct *task) { } -static inline void hw_breakpoint_thread_switch (struct task_struct *next) +static inline void hw_breakpoint_thread_switch (struct task_struct *prev,struct task_struct *next) { }#endif
arch/loongarch/include/asm/loongarch.h +3 -0
@@ -1046,6 +1046,9 @@#define CSR_FWPS_SKIP_SHIFT 16#define CSR_FWPS_SKIP (_ULCAST_(1) << CSR_FWPS_SKIP_SHIFT) +#define CSR_MWPS_SKIP_SHIFT 16 +#define CSR_MWPS_SKIP (_ULCAST_(1) << CSR_MWPS_SKIP_SHIFT) +/* * CSR_ECFG IM */
arch/loongarch/include/asm/processor.h +1 -0
@@ -138,6 +138,7 @@ struct thread_struct {struct loongarch_lbt lbt;/* Also conditionally copied */ /* Hardware breakpoints pinned to this task. */ +bool hbp_break_skip, hbp_watch_skip;struct perf_event *hbp_break[LOONGARCH_MAX_BRP ];struct perf_event *hbp_watch[LOONGARCH_MAX_WRP ]; };
arch/loongarch/include/asm/switch_to.h +1 -1
@@ -36,7 +36,7 @@ extern asmlinkage struct task_struct *__switch_to(struct task_struct *prev,do { \lose_fpu_inatomic (1 , prev); \lose_lbt_inatomic (1 , prev); \ -hw_breakpoint_thread_switch (next); \ +hw_breakpoint_thread_switch (prev, next); \ (last) =__switch_to (prev, next,task_thread_info (next), \__builtin_return_address (0 ),__builtin_frame_address (0 )); \ }while (0 )
arch/loongarch/kernel/hw_breakpoint.c +34 -5
@@ -156,6 +156,9 @@ static int hw_breakpoint_slot_setup(struct perf_event **slots, int max_slots,void ptrace_hw_copy_thread (struct task_struct *tsk) { + tsk->thread.hbp_break_skip =0 ; + tsk->thread.hbp_watch_skip =0 ; +memset (tsk->thread.hbp_break,0 ,sizeof (tsk->thread.hbp_break));memset (tsk->thread.hbp_watch,0 ,sizeof (tsk->thread.hbp_watch)); }
@@ -485,6 +488,7 @@ NOKPROBE_SYMBOL(update_bp_registers);bool breakpoint_handler (struct pt_regs *regs) {int i; +unsigned int clear_mask =0 ;bool need_sigtrap = false;struct perf_event *bp, **slots;
@@ -500,11 +504,13 @@ bool breakpoint_handler(struct pt_regs *regs)if (bp->attr.sigtrap) need_sigtrap = true; -csr_write32 (0x1 << i,LOONGARCH_CSR_FWPS ); -update_bp_registers (regs,0 ,0 ); + clear_mask |= (0x1 << i); } } +if (clear_mask) +csr_write32 (clear_mask |CSR_FWPS_SKIP ,LOONGARCH_CSR_FWPS ); +return need_sigtrap; }NOKPROBE_SYMBOL (breakpoint_handler);
@@ -512,6 +518,7 @@ NOKPROBE_SYMBOL(breakpoint_handler);bool watchpoint_handler (struct pt_regs *regs) {int i; +unsigned int clear_mask =0 ;bool need_sigtrap = false;struct perf_event *wp, **slots;
@@ -527,11 +534,13 @@ bool watchpoint_handler(struct pt_regs *regs)if (wp->attr.sigtrap) need_sigtrap = true; -csr_write32 (0x1 << i,LOONGARCH_CSR_MWPS ); -update_bp_registers (regs,0 ,1 ); + clear_mask |= (0x1 << i); } } +if (clear_mask) +csr_write32 (clear_mask |CSR_MWPS_SKIP ,LOONGARCH_CSR_MWPS ); +return need_sigtrap; }NOKPROBE_SYMBOL (watchpoint_handler);
@@ -555,7 +564,7 @@ static int __init arch_hw_breakpoint_init(void) }arch_initcall (arch_hw_breakpoint_init); -void hw_breakpoint_thread_switch (struct task_struct *next) +void hw_breakpoint_thread_switch (struct task_struct *prev,struct task_struct *next) {u64 addr, mask;struct pt_regs *regs =task_pt_regs (next);
@@ -567,6 +576,26 @@ void hw_breakpoint_thread_switch(struct task_struct *next)csr_write32 (CSR_FWPS_SKIP ,LOONGARCH_CSR_FWPS ); regs->csr_prmd |=CSR_PRMD_PWE ; }else { +unsigned int fwps =csr_read32 (LOONGARCH_CSR_FWPS ); +unsigned int mwps =csr_read32 (LOONGARCH_CSR_MWPS ); + + prev->thread.hbp_break_skip = !!(fwps &CSR_FWPS_SKIP ); + prev->thread.hbp_watch_skip = !!(mwps &CSR_MWPS_SKIP ); + +if (!next->thread.hbp_break_skip) +csr_write32 (0 ,LOONGARCH_CSR_FWPS ); +else { +csr_write32 (CSR_FWPS_SKIP ,LOONGARCH_CSR_FWPS ); + next->thread.hbp_break_skip =0 ; + } + +if (!next->thread.hbp_watch_skip) +csr_write32 (0 ,LOONGARCH_CSR_MWPS ); +else { +csr_write32 (CSR_MWPS_SKIP ,LOONGARCH_CSR_MWPS ); + next->thread.hbp_watch_skip =0 ; + } +/* Update breakpoints */ update_bp_registers (regs,1 ,0 );/* Update watchpoints */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1795/3318 ceph: validate MDS reply fragtree split array length
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: sung byeongchan <[email protected]>
[ Upstream commit 8cab7e7461f81ea1e0fd45082b50bb3c04c0bb10 ]
parse_reply_info_in() advances over the fragtree split array using an unchecked count multiplication. On a 32-bit client, nsplits=0x20000000 wraps the byte length to zero, so the reply is accepted and ceph_fill_fragtree() sorts far beyond the message front.
Compute the split length with size_mul() and require the complete array to remain in the inode record before advancing the cursor.
The malformed reply faulted in frag_tree_split_cmp() twice on the tested i386 baseline. It was rejected without a fault twice after this change, while a normal reply and a one-split control remained functional.
--- fs/ceph/mds_client.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/ceph/mds_client.c +7 -3
@@ -13,6 +13,7 @@#include <linux/bits.h> #include <linux/ktime.h> #include <linux/bitmap.h> +#include <linux/overflow.h> #include "super.h" #include "mds_client.h"
@@ -103,6 +104,7 @@ static int parse_reply_info_in(void **p, void *end, u64 features) {int err =0 ; +size_t splits_len;u8 struct_v =0 ;if (features == (u64)-1 ) {
@@ -121,9 +123,11 @@ static int parse_reply_info_in(void **p, void *end,ceph_decode_need (p, end,sizeof (struct ceph_mds_reply_inode ), bad); info->in = *p; - *p +=sizeof (struct ceph_mds_reply_inode ) + -sizeof (*info->in->fragtree.splits) * -le32_to_cpu (info->in->fragtree.nsplits); + splits_len =size_mul (sizeof (*info->in->fragtree.splits), +le32_to_cpu (info->in->fragtree.nsplits)); + *p +=sizeof (struct ceph_mds_reply_inode ); +ceph_decode_need (p, end, splits_len, bad); + *p += splits_len;ceph_decode_32_safe (p, end, info->symlink_len, bad);ceph_decode_need (p, end, info->symlink_len, bad);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1796/3318 f2fs: fix to adjust appropirate defragment pg_end
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiguo Niu <[email protected]>
[ Upstream commit 197080156f27b6bf8cf198e9313dfbb94769c736 ]
A length that exceeds the real size of the inode may be specified from user, although these out-of-range areas are not mapped, but they still need to be check in while loop, which is unnecessary.
Stable-dep-of: 92154fe28c37 ("f2fs: fix defragment writeback range truncation on 32-bit")
--- fs/f2fs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/f2fs/file.c +7 -5
@@ -2874,12 +2874,13 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,bool fragmented = false;int err; - pg_start = range->start >>PAGE_SHIFT ; - pg_end = (range->start + range->len) >>PAGE_SHIFT ; -f2fs_balance_fs (sbi, true);inode_lock (inode); + pg_start = range->start >>PAGE_SHIFT ; + pg_end =min_t (pgoff_t, + (range->start + range->len) >>PAGE_SHIFT , +DIV_ROUND_UP (i_size_read (inode),PAGE_SIZE ));if (is_inode_flag_set (inode,FI_COMPRESS_RELEASED ) ||f2fs_is_atomic_file (inode)) {
@@ -2895,8 +2896,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, }/* writeback all dirty pages in the range */ - err =filemap_write_and_wait_range (inode->i_mapping, range->start, - range->start + range->len -1 ); + err =filemap_write_and_wait_range (inode->i_mapping, + pg_start <<PAGE_SHIFT , + (pg_end <<PAGE_SHIFT ) -1 );if (err) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1797/3318 f2fs: fix defragment writeback range truncation on 32-bit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
[ Upstream commit 92154fe28c3701bebf75176dc5522bec62519a8f ]
f2fs_defragment_range() flushes the range it is about to defragment:
filemap_write_and_wait_range(inode->i_mapping, pg_start << PAGE_SHIFT, (pg_end << PAGE_SHIFT) - 1);
pg_start and pg_end are pgoff_t, 32 bits on 32-bit kernels, so both shifts are evaluated in 32 bits and truncated before they are widened to the loff_t parameters. pg_end is only capped by the file's page count, so for a file larger than 4 GiB the shift wraps.
For a 5 GiB file pg_end is 1310720 and the range collapses from [0, 5 GiB) to [0, 1 GiB), leaving the rest of the dirty pages unwritten before the blocks are moved. For 8 GiB the shift yields 0, the minus one makes it (loff_t)-1, and the range becomes [0, LLONG_MAX].
The matching call in f2fs_collapse_range() already casts:
filemap_write_and_wait_range(inode->i_mapping, (loff_t)index << PAGE_SHIFT, ((loff_t)pg_end << PAGE_SHIFT) - 1);
Do the same here. On i386 the shift changes from "shl $0xc,%ecx" to "shld", i.e. from a 32-bit shift to a double-precision one.
--- fs/f2fs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/file.c +2 -2
@@ -2897,8 +2897,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,/* writeback all dirty pages in the range */ err =filemap_write_and_wait_range (inode->i_mapping, - pg_start <<PAGE_SHIFT , - (pg_end <<PAGE_SHIFT ) -1 ); + (loff_t )pg_start <<PAGE_SHIFT , + ((loff_t )pg_end <<PAGE_SHIFT ) -1 );if (err) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1798/3318 ocfs2: fix oob in __ocfs2_find_path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Edward Adam Davis <[email protected]>
[ Upstream commit e0b0f2834c9bec51b1068de5cf5e10c7519143eb ]
syzbot constructed a corrupted image, which resulted in el->l_count from the b-tree extent block being 0. Since the length of the l_recs array depends on l_count, reading its member e_blkno triggered the out-of-bounds access reported by syzbot in [1].
The loop terminates when l_count is 0, similar to when next_free is 0.
[1]
UBSAN: array-index-out-of-bounds in fs/ocfs2/alloc.c:1838:11 index 0 is out of range for type 'struct ocfs2_extent_rec[] __counted_by(l_count)' (aka 'struct ocfs2_extent_rec[]') Call Trace: __ocfs2_find_path+0x606/0xa40 fs/ocfs2/alloc.c:1838 ocfs2_find_leaf+0xab/0x1c0 fs/ocfs2/alloc.c:1946 ocfs2_get_clusters_nocache+0x172/0xc60 fs/ocfs2/extent_map.c:418 ocfs2_get_clusters+0x505/0xa70 fs/ocfs2/extent_map.c:631 ocfs2_extent_map_get_blocks+0x202/0x6a0 fs/ocfs2/extent_map.c:678 ocfs2_read_virt_blocks+0x286/0x930 fs/ocfs2/extent_map.c:1001 ocfs2_read_dir_block fs/ocfs2/dir.c:521 [inline] ocfs2_find_entry_el fs/ocfs2/dir.c:728 [inline] ocfs2_find_entry+0x3e4/0x2090 fs/ocfs2/dir.c:1120 ocfs2_find_files_on_disk+0xdf/0x310 fs/ocfs2/dir.c:2023 ocfs2_lookup_ino_from_name+0x52/0x100 fs/ocfs2/dir.c:2045 _ocfs2_get_system_file_inode fs/ocfs2/sysfile.c:136 [inline] ocfs2_get_system_file_inode+0x326/0x770 fs/ocfs2/sysfile.c:112 ocfs2_init_global_system_inodes+0x319/0x660 fs/ocfs2/super.c:461 ocfs2_initialize_super fs/ocfs2/super.c:2196 [inline] ocfs2_fill_super+0x4432/0x65b0 fs/ocfs2/super.c:993 get_tree_bdev_flags+0x40e/0x4d0 fs/super.c:1691 vfs_get_tree+0x92/0x2a0 fs/super.c:1751 fc_mount fs/namespace.c:1199 [inline]
Stable-dep-of: 6193ce7896af ("ocfs2: fix array out of bound access in __ocfs2_find_path()")
--- fs/ocfs2/alloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/ocfs2/alloc.c +5 -4
@@ -1804,14 +1804,15 @@ static int __ocfs2_find_path(struct ocfs2_caching_info *ci, ret = -EROFS ; goto out; } -if (le16_to_cpu (el->l_next_free_rec) ==0 ) { +if (!el->l_next_free_rec || !el->l_count) {ocfs2_error (ocfs2_metadata_cache_get_super (ci), -"Owner %llu has empty extent list at depth %u\n" , +"Owner %llu has empty extent list at depth %u\n" +"(next free=%u count=%u)\n" , (unsigned long long )ocfs2_metadata_cache_owner (ci), -le16_to_cpu (el->l_tree_depth)); +le16_to_cpu (el->l_tree_depth), +le16_to_cpu (el->l_next_free_rec),le16_to_cpu (el->l_count)); ret = -EROFS ; goto out; - }for (i =0 ; i <le16_to_cpu (el->l_next_free_rec) -1 ; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1799/3318 ocfs2: fix array out of bound access in __ocfs2_find_path()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giorgi Kobakhia <[email protected]>
[ Upstream commit 6193ce7896afb52a321a0063c8b6a45e477a84e2 ]
__ocfs2_find_path() walks down the extent tree and records path by calling find_path_ins(), which appends entry to path->p_node[]. It only has 5 spots.
A corrupted ocfs2 image whose extent block is pointing to itself causes __ocfs2_find_path() descent endlessly, writing past the end of path->p_node[] array.
UBSAN: array-index-out-of-bounds in fs/ocfs2/alloc.c:677:14 index 5 is out of range for type 'ocfs2_path_item [5]' Call Trace: <TASK> find_path_ins (fs/ocfs2/alloc.c:677 fs/ocfs2/alloc.c:1914) __ocfs2_find_path.constprop.0 (fs/ocfs2/alloc.c:1882) ocfs2_commit_truncate (fs/ocfs2/alloc.c:1924 fs/ocfs2/alloc.c:7286) ocfs2_truncate_file (fs/ocfs2/file.c:515) ocfs2_setattr (fs/ocfs2/file.c:1224) notify_change (fs/attr.c:556) do_truncate (fs/open.c:68) do_ftruncate (fs/open.c:194 (discriminator 1)) ksys_ftruncate (fs/open.c:206) __x64_sys_ftruncate (fs/open.c:211 fs/open.c:209 fs/open.c:209)
Commit a406aff8c051 ("ocfs2: validate l_tree_depth to avoid out-of-bounds access") already restricts el->l_tree_depth to be less than OCFS2_MAX_PATH_DEPTH, which is equal to 5. However, does not handle the infinite descent case.
Check if the el->l_tree_depth decreases on each descent. Maximum descents are restricted to 4 and the path->p_node[] array does not overflow.
--- fs/ocfs2/alloc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/ocfs2/alloc.c +6 -3
@@ -1789,6 +1789,7 @@ static int __ocfs2_find_path(struct ocfs2_caching_info *ci,int i, ret =0 ;u32 range;u64 blkno; +u32 prev_depth =OCFS2_MAX_PATH_DEPTH ;struct buffer_head *bh =NULL ;struct ocfs2_extent_block *eb;struct ocfs2_extent_list *el;
@@ -1796,14 +1797,16 @@ static int __ocfs2_find_path(struct ocfs2_caching_info *ci, el = root_el;while (el->l_tree_depth) { -if (unlikely (le16_to_cpu (el->l_tree_depth) >=OCFS2_MAX_PATH_DEPTH )) { +if (unlikely (le16_to_cpu (el->l_tree_depth) >= prev_depth)) {ocfs2_error (ocfs2_metadata_cache_get_super (ci), -"Owner %llu has invalid tree depth %u in extent list\n" , +"Owner %llu has invalid tree depth %u in extent list (max %u)\n" , (unsigned long long )ocfs2_metadata_cache_owner (ci), -le16_to_cpu (el->l_tree_depth)); +le16_to_cpu (el->l_tree_depth), prev_depth -1 ); ret = -EROFS ; goto out; } + prev_depth =le16_to_cpu (el->l_tree_depth); +if (!el->l_next_free_rec || !el->l_count) {ocfs2_error (ocfs2_metadata_cache_get_super (ci), "Owner %llu has empty extent list at depth %u\n"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1800/3318 signalfd: dont dequeue the forced fatal signals
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleg Nesterov <[email protected]>
[ Upstream commit d72e0fb3b00c6a1146bcfd7186ad9f6f609ba236 ]
These signals should act like SIGKILL, in that userspace must never dequeue them. But as Kusaram explains, io_uring-driven signalfd_read_iter() called from get_signal() -> task_work_run() paths can do this before get_signal() has a chance to dequeue such a signal and notice SA_IMMUTABLE.
Change signalfd_poll() and signalfd_dequeue() to add pending SA_IMMUTABLE signals to ctx->sigmask.
TODO: we should probably change force_sig_info_to_task(HANDLER_EXIT) to make fatal_signal_pending() true, or add a fatal_or_forced_signal_pending() helper. Then signalfd_dequeue() could just return -EINTR in this case. This also makes sense for get_signal(), which could prioritize a fatal signal sent by (say) force_sig_seccomp(force_coredump => true), just like it already prioritizes SIGKILL.
--- fs/signalfd.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
fs/signalfd.c +22 -6
@@ -48,17 +48,30 @@ static int signalfd_release(struct inode *inode, struct file *file)return 0 ; } +static void refine_sigmask (struct signalfd_ctx *ctx,sigset_t *sigmask) +{ +struct k_sigaction *k = current->sighand->action; +int n; + + *sigmask = ctx->sigmask; +for (n =1 ; n <= _NSIG; ++n, ++k) { +if (k->sa.sa_flags &SA_IMMUTABLE ) +sigaddset (sigmask, n); + } +} +static __poll_t signalfd_poll (struct file *file,poll_table *wait) {struct signalfd_ctx *ctx = file->private_data;__poll_t events =0 ; +sigset_t sigmask;poll_wait (file, ¤t->sighand->signalfd_wqh, wait);spin_lock_irq (¤t->sighand->siglock); -if (next_signal (¤t->pending, &ctx->sigmask) || -next_signal (¤t->signal->shared_pending, - &ctx->sigmask)) +refine_sigmask (ctx, &sigmask); +if (next_signal (¤t->pending, &sigmask) || +next_signal (¤t->signal->shared_pending, &sigmask)) events |=EPOLLIN ;spin_unlock_irq (¤t->sighand->siglock);
@@ -156,11 +169,13 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *info int nonblock) {enum pid_type type; -ssize_t ret;DECLARE_WAITQUEUE (wait, current); +sigset_t sigmask; +ssize_t ret;spin_lock_irq (¤t->sighand->siglock); - ret =dequeue_signal (current, &ctx->sigmask, info, &type); +refine_sigmask (ctx, &sigmask); + ret =dequeue_signal (current, &sigmask, info, &type);switch (ret) {case 0 :if (!nonblock)
@@ -175,7 +190,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infoadd_wait_queue (¤t->sighand->signalfd_wqh, &wait);for (;;) {set_current_state (TASK_INTERRUPTIBLE ); - ret =dequeue_signal (current, &ctx->sigmask, info, &type); + ret =dequeue_signal (current, &sigmask, info, &type);if (ret !=0 )break ;if (signal_pending (current)) {
@@ -185,6 +200,7 @@ static ssize_t signalfd_dequeue(struct signalfd_ctx *ctx, kernel_siginfo_t *infospin_unlock_irq (¤t->sighand->siglock);schedule ();spin_lock_irq (¤t->sighand->siglock); +refine_sigmask (ctx, &sigmask); }spin_unlock_irq (¤t->sighand->siglock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1801/3318 PCI: cadence: Store the core controller in platform drvdata
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
[ Upstream commit cfe96ce583c51bf6e034d4038c652a1e8227867c ]
cdns_plat_pcie_probe() stores a struct cdns_plat_pcie pointer with platform_set_drvdata(). cdns_plat_pcie_shutdown() and the callbacks in cdns_pcie_pm_ops retrieve the same pointer with dev_get_drvdata() but use it as a struct cdns_pcie pointer. This makes them read phy_count and phy beyond the wrapper.
struct cdns_plat_pcie only contains a pointer to struct cdns_pcie. Drop the redundant wrapper and store the struct cdns_pcie pointer directly.
--- .../controller/cadence/pcie-cadence-plat.c | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-)
drivers/pci/controller/cadence/pcie-cadence-plat.c +10 -26
@@ -14,17 +14,6 @@#define CDNS_PLAT_CPU_TO_BUS_ADDR 0x0FFFFFFF -/** -* struct cdns_plat_pcie - private data for this PCIe platform driver -* @pcie: Cadence PCIe controller -* @is_rc: Set to 1 indicates the PCIe controller mode is Root Complex, -* if 0 it is in Endpoint mode. -*/ -struct cdns_plat_pcie { -struct cdns_pcie *pcie; -bool is_rc; -}; -struct cdns_plat_pcie_of_data {bool is_rc; };
@@ -43,9 +32,9 @@ static const struct cdns_pcie_ops cdns_plat_ops = {static int cdns_plat_pcie_probe (struct platform_device *pdev) {const struct cdns_plat_pcie_of_data *data; -struct cdns_plat_pcie *cdns_plat_pcie;struct device *dev = &pdev->dev;struct pci_host_bridge *bridge; +struct cdns_pcie *pcie;struct cdns_pcie_ep *ep;struct cdns_pcie_rc *rc;int phy_count;
@@ -59,11 +48,6 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev) is_rc = data->is_rc;pr_debug (" Started %s with is_rc: %d\n" , __func__, is_rc); - cdns_plat_pcie =devm_kzalloc (dev,sizeof (*cdns_plat_pcie),GFP_KERNEL ); -if (!cdns_plat_pcie) -return -ENOMEM ; - -platform_set_drvdata (pdev, cdns_plat_pcie);if (is_rc) {if (!IS_ENABLED (CONFIG_PCIE_CADENCE_PLAT_HOST ))return -ENODEV ;
@@ -75,10 +59,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev) rc =pci_host_bridge_priv (bridge); rc->pcie.dev = dev; rc->pcie.ops = &cdns_plat_ops; - cdns_plat_pcie->pcie = &rc->pcie; - cdns_plat_pcie->is_rc = is_rc; + pcie = &rc->pcie; - ret =cdns_pcie_init_phy (dev, cdns_plat_pcie->pcie); + ret =cdns_pcie_init_phy (dev, pcie);if (ret) {dev_err (dev,"failed to init phy\n" );return ret;
@@ -103,10 +86,9 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev) ep->pcie.dev = dev; ep->pcie.ops = &cdns_plat_ops; - cdns_plat_pcie->pcie = &ep->pcie; - cdns_plat_pcie->is_rc = is_rc; + pcie = &ep->pcie; - ret =cdns_pcie_init_phy (dev, cdns_plat_pcie->pcie); + ret =cdns_pcie_init_phy (dev, pcie);if (ret) {dev_err (dev,"failed to init phy\n" );return ret;
@@ -124,16 +106,18 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev) goto err_init; } +platform_set_drvdata (pdev, pcie); +return 0 ; err_init: err_get_sync:pm_runtime_put_sync (dev);pm_runtime_disable (dev); -cdns_pcie_disable_phy (cdns_plat_pcie->pcie); - phy_count = cdns_plat_pcie->pcie->phy_count; +cdns_pcie_disable_phy (pcie); + phy_count = pcie->phy_count;while (phy_count--) -device_link_del (cdns_plat_pcie->pcie->link[phy_count]); +device_link_del (pcie->link[phy_count]);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1802/3318 PCI: cadence: Preserve all error codes in cdns_plat_pcie_probe()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Oltean <[email protected]>
[ Upstream commit fe108800a865b268eec103e4940c248c85a86e9f ]
The blamed commit functionally changed the error path of cdns_pcie_host_probe(), now cdns_plat_pcie_probe().
When the old code path executed "goto err_get_sync", the PCIe controller probe function propagated the pm_runtime_get_sync() error code. The new code doesn't, and returns 0.
Similarly for the "goto err_init" previously triggered by cdns_pcie_host_init() errors, and now triggered by cdns_pcie_host_setup() and cdns_pcie_ep_setup() errors. These are not propagated and will result in probing success, which is incorrect.
--- drivers/pci/controller/cadence/pcie-cadence-plat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/cadence/pcie-cadence-plat.c +1 -1
@@ -119,7 +119,7 @@ static int cdns_plat_pcie_probe(struct platform_device *pdev)while (phy_count--)device_link_del (pcie->link[phy_count]); -return 0 ; +return ret; }static void cdns_plat_pcie_shutdown (struct platform_device *pdev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1803/3318 media: qcom: camss: vfe-17x: Fix write master selection for RDI lines
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hitesh Patel <[email protected]>
[ Upstream commit fc02156a3efb747b724a490cc50e1ad8c28a3b23 ]
On the gen2 VFE bus there is no crossbar between the RDI paths and the bus write masters: RDI n is served by write master n. The common vfe_get_output_v2() reflects this by mapping line->id to write master line->id, and every gen2 VFE except 17x uses it.
The 17x code kept its own vfe_get_output(), which reserves whichever write master is free first. That happens to be the right one as long as a single line streams and it is RDI0. As soon as two lines of the same VFE stream, for instance two virtual channels demultiplexed by the CSID to RDI0 and RDI1, the second line to start is given the write master of the other RDI. Both write masters are then programmed with the buffer address and frame size of the wrong line. The frames are truncated to the smaller of the two buffers and the SMMU faults on the larger one.
Use vfe_get_output_v2() on 17x like the other gen2 VFEs and drop the duplicate. This also removes an error path that released output->wm_idx[0] before it had been assigned.
The gen1 VFEs are not affected: they have a bus crossbar and any write master can serve any line, so vfe_reserve_wm() is correct there.
--- .../media/platform/qcom/camss/camss-vfe-170.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/media/platform/qcom/camss/camss-vfe-170.c +7 -10
@@ -402,7 +402,6 @@ static int vfe_get_output(struct vfe_line *line)struct vfe_device *vfe =to_vfe (line);struct vfe_output *output;unsigned long flags; -int wm_idx;spin_lock_irqsave (&vfe->output_lock, flags);
@@ -414,12 +413,12 @@ static int vfe_get_output(struct vfe_line *line) output->wm_num =1 ; - wm_idx =vfe_reserve_wm (vfe, line->id); -if (wm_idx <0 ) { -dev_err (vfe->camss->dev,"Can not reserve wm\n" ); - goto error_get_wm; - } - output->wm_idx[0 ] = wm_idx; +/* Correspondence between VFE line number and WM number. +* line 0 -> RDI 0, line 1 -> RDI1, line 2 -> RDI2, line 3 -> PIX/RDI3 +* Note this 1:1 mapping will not work for PIX streams. +*/ + output->wm_idx[0 ] = line->id; + vfe->wm_output_map[line->id] = line->id; output->drop_update_idx =0 ;
@@ -427,11 +426,9 @@ static int vfe_get_output(struct vfe_line *line)return 0 ; -error_get_wm: -vfe_release_wm (vfe, output->wm_idx[0 ]); - output->state =VFE_OUTPUT_OFF ; error:spin_unlock_irqrestore (&vfe->output_lock, flags); + output->state =VFE_OUTPUT_OFF ;return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1804/3318 iomap: dont mark unwritten parts of a folio uptodate
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit a4193b4af359db84b2cdf3a040752861984c636b ]
For a buffered write into a hole, an unwritten or new extent, or past EOF __iomap_write_begin() zeroes the parts of the blocks outside of the write and then marks the blocks uptodate. That includes the range of the write itself which still holds whatever was in the folio before. It only becomes valid once the copy from userspace has filled it in.
But the copy can come up short and __iomap_write_end() only rejects a short copy if the folio isn't uptodate. If the zeroed blocks were all that was missing the folio is uptodate by then, the short copy is accepted, and the rest of the range is exposed to readers and can end up on disk. A source buffer that ends in an unmapped page is enough:
ftruncate(fd, 4096);
pwrite(fd, p, 3000, 100); /* 16 bytes at p, then PROT_NONE */
pread(fd, buf, 4096, 0);The write returns 16 and the read returns 2984 bytes of whatever was in that page before. If other blocks of the folio aren't uptodate the short copy is rejected but the zeroed blocks keep their uptodate bits and the retry with the copied length leaves the same bytes behind.
Only mark blocks uptodate in __iomap_write_begin() after reading them. __iomap_write_end() marks the zeroed blocks uptodate once the copy has succeeded and rejects a short copy.
Willy reported this back in 2024 (cf. [1]) and Zhang Yi posted the same fix (cf. [2]) but it never got merged.
[1]: https://lore.kernel.org/all/[email protected]
[2]: https://lore.kernel.org/all/[email protected]
--- fs/iomap/buffered-io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +2 -1
@@ -710,6 +710,7 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,if (iomap_block_needs_zeroing (iter, block_start)) {if (WARN_ON_ONCE (iter->flags &IOMAP_UNSHARE ))return -EIO ; +/* uptodate once copied, see __iomap_write_end() */ folio_zero_segments (folio, poff, from, to, poff + plen); }else {int status;
@@ -721,8 +722,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, poff, plen, srcmap);if (status)return status; +iomap_set_range_uptodate (folio, poff, plen); } -iomap_set_range_uptodate (folio, poff, plen); }while ((block_start += plen) < block_end);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1805/3318 media: serial_ir: Fix race condition where timer can be re-armed
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit d74ac4016ba64cb3b20f395511d0b18025ca0ba9 ]
Ensure the timer cannot be re-armed.
--- drivers/media/rc/serial_ir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/rc/serial_ir.c +1 -1
@@ -797,7 +797,7 @@ static int __init serial_ir_init_module(void) static void __exit serial_ir_exit_module(void) { -del_timer_sync (&serial_ir.timeout_timer); +timer_shutdown_sync (&serial_ir.timeout_timer);serial_ir_exit (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1806/3318 gpiolib: cdev: dont set GPIOD_FLAG_IS_OUT
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Ambrozewicz <[email protected]>
[ Upstream commit 974d2712cb15014019595799b3ed68fef5fe9695 ]
When a line is requested or reconfigured through the v2 uAPI, gpio_v2_line_config_flags_to_desc_flags() copies the requested configuration into the descriptor flags, GPIOD_FLAG_IS_OUT included, before gpiod_direction_input_nonotify() or gpiod_direction_output_nonotify() asks the driver for the direction. If the driver refuses, for instance with -EOPNOTSUPP from .direction_input() for a line that can only be an output, the ioctl fails but the flag keeps the refused direction. gpiod_free_commit() does not touch GPIOD_FLAG_IS_OUT, so this outlives the failed request, and GPIO_V2_GET_LINEINFO_IOCTL reports the line as an input while the hardware still drives it, until a request without direction flags makes gpiod_request_commit() read the direction back from the driver:
GPIO_V2_GET_LINE_IOCTL, line 0, input: -EOPNOTSUPP GPIO_V2_GET_LINEINFO_IOCTL, line 0: input GPIO_V2_GET_LINE_IOCTL, line 0, no direction: ok GPIO_V2_GET_LINEINFO_IOCTL, line 0: output
GPIO_V2_LINE_SET_CONFIG_IOCTL updates the flags in the same order. There the line stays requested, and since commit 92ac7de3175e ("gpiolib: don't allow setting values on input lines") GPIO_V2_LINE_SET_VALUES_IOCTL on it then fails with -EPERM, though the line is still an output. A line whose driver refuses to make it an output is likewise reported as one.
gpiod_direction_input_nonotify() and gpiod_direction_output_nonotify() set or clear GPIOD_FLAG_IS_OUT themselves once the driver has accepted the direction, emulated open drain and open source included, and nothing between the copy and those calls reads the flag. Leave it to them, as the v1 uAPI already does.
The other flags that the helper copies stay as they are. Active low, drive and bias are what gpiod_direction_*() applies, drive and bias possibly before the driver refuses the direction; edges and event clock are the character device's own. None of them is read back from the driver, so there is no earlier state that is more accurate to go back to. A failed request releases the line, which clears them, and a failed reconfiguration leaves the line, like the lines before it, with what was applied up to the failure.
Reproduced under QEMU with a test GPIO chip whose line 0 refuses input and line 1 refuses output: both refused requests and both refused reconfigurations leave the line info with the refused direction, and setting the value of the reconfigured output fails with -EPERM. With this change the line info shows the direction of the hardware in all four cases and setting the value works. First seen on real hardware with v6.12.
--- drivers/gpio/gpiolib-cdev.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/gpio/gpiolib-cdev.c +0 -5
@@ -1417,11 +1417,6 @@ static void gpio_v2_line_config_flags_to_desc_flags(u64 flags,assign_bit (FLAG_ACTIVE_LOW , flagsp, flags &GPIO_V2_LINE_FLAG_ACTIVE_LOW ); -if (flags &GPIO_V2_LINE_FLAG_OUTPUT ) -set_bit (FLAG_IS_OUT , flagsp); -else if (flags &GPIO_V2_LINE_FLAG_INPUT ) -clear_bit (FLAG_IS_OUT , flagsp); -assign_bit (FLAG_EDGE_RISING , flagsp, flags &GPIO_V2_LINE_FLAG_EDGE_RISING ); assign_bit(FLAG_EDGE_FALLING, flagsp,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1807/3318 ACPI: APEI: accumulate the queued flag across error sections
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit f341307a14895e5da056fb419a31ef7fb534ab18 ]
ghes_do_proc() walks every error section of a CPER record, and ghes_handle_arm_hw_error() walks every error-info entry of an ARM processor section. Both assign to "queued" instead of OR-ing into it, so only the last iteration counts: a later section or entry that queues no memory-failure work clears the flag an earlier one set.
Instead of reassigning the variable at every time, just do an OR, so, if there was a single match, it will return "queued" as set.
The comment above the check says "If no memory failure
work is queued", which is the semantics this patch implements. I.e, only SIGBUS if there are queue was not handled at all. If we want to SIGBUS if any event was not handled/queued at all, we will need something more sophisticated.
--- drivers/acpi/apei/ghes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/acpi/apei/ghes.c +3 -3
@@ -557,7 +557,7 @@ static bool ghes_handle_arm_hw_error(struct acpi_hest_generic_data *gdata,* and don't filter out 'corrected' error here. */ if (is_cache && has_pa) { - queued =ghes_do_memory_failure (err_info->physical_fault_addr, flags); + queued |=ghes_do_memory_failure (err_info->physical_fault_addr, flags); p += err_info->length;continue ; }
@@ -706,13 +706,13 @@ static bool ghes_do_proc(struct ghes *ghes,atomic_notifier_call_chain (&ghes_report_chain, sev, mem_err);arch_apei_report_mem_error (sev, mem_err); - queued =ghes_handle_memory_failure (gdata, sev, sync); + queued |=ghes_handle_memory_failure (gdata, sev, sync); }else if (guid_equal (sec_type, &CPER_SEC_PCIE )) {ghes_handle_aer (gdata); }else if (guid_equal (sec_type, &CPER_SEC_PROC_ARM )) { - queued =ghes_handle_arm_hw_error (gdata, sev, sync); + queued |=ghes_handle_arm_hw_error (gdata, sev, sync); }else {void *err =acpi_hest_get_payload (gdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1808/3318 posix-timers: Report zero remaining time for disarmed SIGEV_NONE timers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hung-Jui Lin <[email protected]>
[ Upstream commit 141a27750ec3d91ad9d1ad1764ebb5e51b963478 ]
SIGEV_NONE timers are never queued. common_timer_get() emulates their expiry by computing the remaining time from the stored expiry value. Because an armed SIGEV_NONE oneshot timer is not queued, its it_status stays POSIX_TIMER_DISARMED. So common_timer_get() cannot use it_status to skip a disarmed SIGEV_NONE timer and evaluates the stored expiry value for all SIGEV_NONE timers.
Disarming a timer with timer_settime() and a zero it_value cancels the timer and sets it_status to POSIX_TIMER_DISARMED, but leaves the expiry value unchanged. As a consequence, timer_gettime() on a disarmed SIGEV_NONE timer reports the remaining time of the previous arming until that time has passed, instead of zero as POSIX requires for a disarmed timer. Example with a CLOCK_MONOTONIC timer armed with it_value = 10ms and it_interval = 100ms, then disarmed with an all-zero itimerspec:
armed: it_value = 0.009999000 it_interval = 0.100000000
disarmed: it_value = 0.008700792 it_interval = 0.000000000
SIGEV_SIGNAL timers and SIGEV_NONE CPU timers report zero in the same situation. All clocks which use common_timer_get() are affected, including the alarm timer clocks.
Mark SIGEV_NONE timers as POSIX_TIMER_ARMED when they are armed, so that common_timer_get() returns early for every disarmed timer. Forward SIGEV_NONE interval timers in common_timer_get() regardless of it_status, as they are never queued and therefore never forwarded by the expiry code.
After the change the disarmed timer above reports zero. Armed SIGEV_NONE oneshot and interval timers on CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME and CLOCK_BOOTTIME_ALARM still report their remaining time, and the posix_timers selftest passes.
--- kernel/time/posix-timers.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/time/posix-timers.c +11 -11
@@ -648,16 +648,8 @@ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)if (iv) { cur_setting->it_interval =ktime_to_timespec64 (iv); }else if (!timr->it_active) { -/* -* SIGEV_NONE oneshot timers are never queued and therefore -* timr->it_active is always false. The check below -* vs. remaining time will handle this case. -* -* For all other timers there is nothing to update here, so -* return. -*/ -if (!sig_none) -return ; +/* Nothing to update for a disarmed timer */ +return ; } now = kc->clock_get_ktime (timr->it_clock);
@@ -894,7 +886,15 @@ int common_timer_set(struct k_itimer *timr, int flags, sigev_none = timr->it_sigev_notify ==SIGEV_NONE ; kc->timer_arm (timr, expires, flags &TIMER_ABSTIME , sigev_none); - timr->it_active = !sigev_none; +/* +* SIGEV_NONE timers are not queued, but mark them armed +* so that common_timer_get() can tell them apart from +* disarmed timers. An expired SIGEV_NONE timer stays +* armed, which is harmless: common_timer_get() reports +* zero remaining time for it and it never reaches the +* signal delivery code. +*/ + timr->it_active =1 ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1809/3318 dax: fix wrong error code returned from dax_dedupe_file_range_compare()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianyun Gao <[email protected]>
[ Upstream commit 9b036546a02c6c9a5133f9c1e93503896595c6ba ]
When dax_range_compare_iter() returns a negative error code (e.g. -EIO), dax_dedupe_file_range_compare() incorrectly returns 'ret' which holds the positive return value from iomap_iter() indicating more iterations remain. This positive value leaks to the caller, where vfs_dedupe_file_range() interprets it as success (bytes_deduped = len), causing userspace to incorrectly believe deduplication completed.
Return 'status' instead to propagate the actual error code.
--- fs/dax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dax.c +1 -1
@@ -2067,7 +2067,7 @@ int dax_dedupe_file_range_compare(struct inode *src, loff_t srcoff, compared =dax_range_compare_iter (&src_iter, &dst_iter,min (src_iter.len, dst_iter.len), same);if (compared <0 ) -return ret; +return compared; src_iter.processed = dst_iter.processed = compared; }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1810/3318 mm/mremap: correctly uncharge accountable VMAs in error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 65e722a74df992719676ead85a9e93fb2b5a0983 ]
The mremap error path is a fragile and unwieldy beast - it reverses the page table move then updates vma_remap_struct state to swap VMA, length and address between old and new VMAs in copy_vma_and_data().
If the mremap() operation didn't specify MREMAP_DONTUNMAP then its caller, move_vma(), invokes unmap_source_vma(), which unmaps the new VMA rather than the old one.
For accountable VMAs when MREMAP_DONTUNMAP is not specified, unmap_source_vma() unsets VMA_ACCOUNT_BIT during this unmap in order that only the delta of a VMA expansion is charged (performed by vrm_calc_charge() earlier).
Therefore nothing uncharges the expanded VMA size, and there is a permanent leak in global Committed_AS.
Resolve the issue by uncharging when MREMAP_DONTUNMAP is not specified.
--- mm/mremap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/mremap.c +13 -0
@@ -715,6 +715,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,*/ move_page_tables (new_vma, new_addr, vma, old_addr, moved_len, true); + +/* +* The new VMA will be unmapped rather than the old one. +* +* When an accountable move is being performed, this unmapping +* will not uncharge any expansion, so do that now. +* +* A move is accountable if the VMA is accountable and +* MREMAP_DONTUNMAP is not specified. +*/ +if (vm_flags &VM_ACCOUNT && !(flags &MREMAP_DONTUNMAP )) +vm_unacct_memory (to_account >>PAGE_SHIFT ); + vma = new_vma; old_len = new_len; old_addr = new_addr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1811/3318 PCI: dwc: Set DMA_BYPASS bit in outbound IATU CTRL2 register
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sumit Kumar <[email protected]>
[ Upstream commit efadda401c5c8e2390ba66508eba154dbd0db5a9 ]
An outbound iATU region matches any local (AXI/application-side) address that falls within its Base/Limit window and rewrites it to the PCIe-side address programmed in that region's Target Address Registers before the transaction goes out on the link. This matching does not distinguish CPU-initiated transactions from ones issued by the internal DMA engine (eDMA/HDMA).
Example: outbound region 0 is programmed with Base/Limit covering local addresses 0x8000_0000-0x8000_0FFF and Target 0x1_0000_0000, for CPU-initiated accesses. The DMA engine is later given a descriptor whose destination is the host address 0x8000_0080, which happens to fall inside region 0's Base/Limit range. The iATU matches the DMA transaction against region 0 too and rewrites it to 0x1_0000_0080 instead of passing 0x8000_0080 through unchanged. The transaction then lands on the wrong host address, causing data corruption or an IOMMU fault when the rewritten address has no valid mapping.
Set the DMA_BYPASS bit (bit 27) in PCIE_ATU_REGION_CTRL2 when programming outbound iATU regions so only CPU/AXI-initiated transactions are matched against the region; DMA engine transactions bypass the translation and go out on the PCIe link with their original address.
--- drivers/pci/controller/dwc/pcie-designware.c | 5 ++++- drivers/pci/controller/dwc/pcie-designware.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware.c +4 -1
@@ -506,7 +506,10 @@ static int __dw_pcie_prog_outbound_atu(struct dw_pcie *pci, u8 func_no, val =dw_pcie_enable_ecrc (val);dw_pcie_writel_atu_ob (pci, index,PCIE_ATU_REGION_CTRL1 , val); -dw_pcie_writel_atu_ob (pci, index,PCIE_ATU_REGION_CTRL2 ,PCIE_ATU_ENABLE ); + val =PCIE_ATU_ENABLE ; + if (dw_pcie_ver_is_ge(pci, 460A)) + val |=PCIE_ATU_DMA_BYPASS ; +dw_pcie_writel_atu_ob (pci, index,PCIE_ATU_REGION_CTRL2 , val);/* * Make sure ATU enable takes effect before any subsequent config
drivers/pci/controller/dwc/pcie-designware.h +1 -0
@@ -154,6 +154,7 @@#define PCIE_ATU_REGION_CTRL2 0x004#define PCIE_ATU_ENABLE BIT(31)#define PCIE_ATU_BAR_MODE_ENABLE BIT(30) +#define PCIE_ATU_DMA_BYPASS BIT(27)#define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)#define PCIE_ATU_LOWER_BASE 0x008#define PCIE_ATU_UPPER_BASE 0x00C
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1812/3318 clk: nuvoton: ma35d1: Keep the clock count in the driver
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
[ Upstream commit 26ec588063d9b6c70773b8729372e2bf6d3ea95a ]
The number of clocks is not a binding since this is a value that can change. As such, in order to support the missing watchdog clocks and allow the deprecation and removal of CLK_MAX_IDX from the bindings, we need to switch to a local definition first.
Stable-dep-of: 1dc3871ce7ec ("clk: nuvoton: ma35d1: Add missing WDT/WWDT parent clocks")
--- drivers/clk/nuvoton/clk-ma35d1.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/nuvoton/clk-ma35d1.c +3 -2
@@ -17,6 +17,7 @@static DEFINE_SPINLOCK (ma35d1_lock);#define PLL_MAX_NUM 5 +#define MA35D1_CLK_COUNT 236/* Clock Control Registers Offset */ #define REG_CLK_PWRCTL 0x00
@@ -467,12 +468,12 @@ static int ma35d1_clocks_probe(struct platform_device *pdev)int ret; ma35d1_hw_data =devm_kzalloc (dev, -struct_size (ma35d1_hw_data, hws,CLK_MAX_IDX ), +struct_size (ma35d1_hw_data, hws,MA35D1_CLK_COUNT ),GFP_KERNEL );if (!ma35d1_hw_data)return -ENOMEM ; - ma35d1_hw_data->num =CLK_MAX_IDX ; + ma35d1_hw_data->num =MA35D1_CLK_COUNT ; hws = ma35d1_hw_data->hws; clk_base =devm_platform_ioremap_resource (pdev,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1813/3318 dt-bindings: clock: ma35d1: Drop CLK_MAX_IDX define
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
[ Upstream commit 653738db38c7c7f0fb959a7870f9461cf4987825 ]
Drop CLK_MAX_IDX define of MA35D1 include. This is not a binding and should not be placed here. Value is defined in the user driver.
Stable-dep-of: 1dc3871ce7ec ("clk: nuvoton: ma35d1: Add missing WDT/WWDT parent clocks")
--- include/dt-bindings/clock/nuvoton,ma35d1-clk.h | 1 - 1 file changed, 1 deletion(-)
include/dt-bindings/clock/nuvoton,ma35d1-clk.h +0 -1
@@ -248,6 +248,5 @@#define ADC_GATE 233#define EADC_DIV 234#define EADC_GATE 235 -#define CLK_MAX_IDX 236#endif /* __DT_BINDINGS_CLOCK_NUVOTON_MA35D1_CLK_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1814/3318 dt-bindings: clock: ma35d1: Add missing WDT/WWDT parent clocks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
[ Upstream commit 8c7453cb0b01bee47ec2f902a9ac1872d3b77f3d ]
The WDT and WWDT muxes have PCLK3/4096 and PCLK4/4096 among their possible parents, but these fixed factor clocks are currently not defined, even though they are needed to properly describe the clock tree. Add them to the bindings.
Stable-dep-of: 1dc3871ce7ec ("clk: nuvoton: ma35d1: Add missing WDT/WWDT parent clocks")
--- include/dt-bindings/clock/nuvoton,ma35d1-clk.h | 2 ++ 1 file changed, 2 insertions(+)
include/dt-bindings/clock/nuvoton,ma35d1-clk.h +2 -0
@@ -248,5 +248,7 @@#define ADC_GATE 233#define EADC_DIV 234#define EADC_GATE 235 +#define PCLK3_DIV4096 236 +#define PCLK4_DIV4096 237#endif /* __DT_BINDINGS_CLOCK_NUVOTON_MA35D1_CLK_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1815/3318 clk: nuvoton: ma35d1: Add missing WDT/WWDT parent clocks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal <[email protected]>
[ Upstream commit 1dc3871ce7ec819030c22297f8960c61cc42a990 ]
The WDT and WWDT muxes list PCLK3/4096 and PCLK4/4096 among their possible parents, but the driver never registers the corresponding clocks, so these parents could never be used.
Add pclk3_div4096 and pclk4_div4096 as fixed factor children of pclk3 and pclk4 and expose them through the clock provider.
--- drivers/clk/nuvoton/clk-ma35d1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/nuvoton/clk-ma35d1.c +3 -1
@@ -17,7 +17,7 @@static DEFINE_SPINLOCK (ma35d1_lock);#define PLL_MAX_NUM 5 -#define MA35D1_CLK_COUNT 236 +#define MA35D1_CLK_COUNT 238/* Clock Control Registers Offset */ #define REG_CLK_PWRCTL 0x00
@@ -544,6 +544,8 @@ static int ma35d1_clocks_probe(struct platform_device *pdev) hws[HCLK3 ] =ma35d1_clk_fixed_factor (dev,"hclk3" ,"sysclk1_mux" ,1 ,2 ); hws[PCLK3 ] =ma35d1_clk_fixed_factor (dev,"pclk3" ,"sysclk1_mux" ,1 ,2 ); hws[PCLK4 ] =ma35d1_clk_fixed_factor (dev,"pclk4" ,"sysclk1_mux" ,1 ,2 ); + hws[PCLK3_DIV4096 ] =ma35d1_clk_fixed_factor (dev,"pclk3_div4096" ,"pclk3" ,1 ,4096 ); + hws[PCLK4_DIV4096 ] =ma35d1_clk_fixed_factor (dev,"pclk4_div4096" ,"pclk4" ,1 ,4096 ); hws[USBPHY0 ] =ma35d1_clk_fixed ("usbphy0" ,480000000 ); hws[USBPHY1 ] =ma35d1_clk_fixed ("usbphy1" ,480000000 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1816/3318 f2fs: release a removed xattr node in roll-forward recovery
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daeho Jeong <[email protected]>
[ Upstream commit f5924de8867c09206ba631b9faed63862ec00a10 ]
When xattrs shrink enough to fit in the inline xattr area, write_all_xattrs() truncates the xattr node and clears i_xattr_nid. If the file is then fsynced without a checkpoint, only the inode block is written, with i_xattr_nid of 0.
Roll-forward recovery starts from the checkpointed inode, whose i_xattr_nid still points to the old xattr node. f2fs_recover_inline_xattr() copies only the inline xattr area, and f2fs_update_inode() writes the old i_xattr_nid back. So the inode keeps the stale xattr node:
- The node block is never released, and fsck reports "nonzero bytes in xattr space after end of list".
- If the inline xattr list ends exactly at the end of the inline area, its terminator is read from the stale node, and the removed xattrs come back after recovery.
When the fsynced inode has no xattr node but the checkpointed one has, release the old xattr node as truncate_node() does: check its block address, invalidate the block and drop its node cache, which may still be dirty.
--- fs/f2fs/node.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
fs/f2fs/node.c +39 -0
@@ -2767,6 +2767,45 @@ int f2fs_recover_inline_xattr(struct inode *inode, struct page *page)f2fs_wait_on_page_writeback (ipage,NODE , true, true);memcpy (dst_addr, src_addr, inline_size); update_inode: +/* +* The xattr node of the checkpoint was removed before fsync, e.g. the +* xattrs became small enough to fit inline. Release it as well, or +* the inode keeps pointing to the stale xattrs. +*/ +if (!ri->i_xattr_nid &&F2FS_I (inode)->i_xattr_nid) { +struct f2fs_sb_info *sbi =F2FS_I_SB (inode); +struct node_info ni; +int err; + + err =f2fs_get_node_info (sbi,F2FS_I (inode)->i_xattr_nid, + &ni, false); +if (err) { +f2fs_put_page (ipage,1 ); +return err; + } + +if (ni.blk_addr !=NEW_ADDR && + !f2fs_is_valid_blkaddr (sbi, ni.blk_addr, +DATA_GENERIC_ENHANCE )) { +f2fs_err_ratelimited (sbi, +"nat entry is corrupted, run fsck to fix it, ino:%u, nid:%u, blkaddr:%u" , + ni.ino, ni.nid, ni.blk_addr); +set_sbi_flag (sbi,SBI_NEED_FSCK ); +f2fs_handle_error (sbi,ERROR_INCONSISTENT_NAT ); +f2fs_put_page (ipage,1 ); +return -EFSCORRUPTED ; + } + +f2fs_invalidate_blocks (sbi, ni.blk_addr); +dec_valid_node_count (sbi, inode, false); +set_node_addr (sbi, &ni,NULL_ADDR , false); +/* drop the cached xattr node, which may be dirty */ +truncate_inode_pages_range (NODE_MAPPING (sbi), +F2FS_BLK_TO_BYTES ((loff_t )ni.nid), +F2FS_BLK_END_BYTES ((loff_t )ni.nid)); +f2fs_i_xnid_write (inode,0 ); + } +f2fs_update_inode (inode, ipage);f2fs_put_page (ipage,1 );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1817/3318 mm/vma: avoid broken uffd merge on mremap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
[ Upstream commit 68cb098eadda190783f8f8bdf9fe764df59f7d32 ]
Userfaultfd often causes unexpected interactions within mm, and does so at the intersection of uffd, mremap() and VMA merging.
When an mremap of a VMA occurs, copy_vma_and_data() calls mremap_userfaultfd_prep() to notify uffd of this.
However, mremap_userfaultfd_prep() simply drops the UFFD context for the VMA if the user did not register it for remap, i.e. didn't specify the UFFD_FEATURE_EVENT_REMAP flag.
This is OK for the VMA itself, as upon page table move, move_ptes() clears UFFD page table flags, using vma_has_uffd_without_event_remap() to determine whether to do so.
However, this doesn't account for merging with adjacent VMAs, whose page tables won't have received this treatment, and thus latent UFFD markers will be left around.
Worse, it'll break UFFD for any VMAs it is merged with. This is very surprising behaviour for a user, who will then simply not receive UFFD events for VMAs they ought to.
Resolve the issue by explicitly checking for this case via vma_has_uffd_without_event_remap() in vma_merge_copied_range(), the merge function explicitly designated for mremap() operations.
Also update the userland VMA tests accordingly.
--- mm/mmap.c | 3 +++ 1 file changed, 3 insertions(+)
mm/mmap.c +3 -0
@@ -3426,6 +3426,9 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,if (can_self_merge && keep_source && (addr == vma->vm_end || vma->vm_start == addr + len)) new_vma =NULL ; +else if (vma_has_uffd_without_event_remap (vma)) +/* If not registered for remap, uffd context will be cleared. */ + new_vma =NULL ;else new_vma = vma_merge(&vmi, mm, prev, addr, addr + len, vma->vm_flags, vma->anon_vma, vma->vm_file,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1818/3318 ALSA: aloop: Use guard() for mutex locks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit ebd9b6c91d4e345b7ded4b56567c46267a45d961 ]
Replace the manual mutex lock/unlock pairs with guard() for code simplification.
Only code refactoring, and no behavior change.
Keep the conversions in the format, rate, channels and period-bytes constraint rules, which need automatic unlocking for the notify-mode early returns. The other mutex conversions are unnecessary for that change, and the access-mode control is absent.
Stable-dep-of: ded106036984 ("ALSA: aloop: Don't constrain playback params in notify mode")
--- sound/drivers/aloop.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
sound/drivers/aloop.c +16 -16
@@ -952,10 +952,10 @@ static int rule_format(struct snd_pcm_hw_params *params,struct snd_mask m;snd_mask_none (&m); -mutex_lock (&dpcm->loopback->cable_lock); - m.bits[0 ] = (u_int32_t )cable->hw.formats; - m.bits[1 ] = (u_int32_t)(cable->hw.formats >>32 ); -mutex_unlock (&dpcm->loopback->cable_lock); + scoped_guard(mutex, &dpcm->loopback->cable_lock) { + m.bits[0 ] = (u_int32_t )cable->hw.formats; + m.bits[1 ] = (u_int32_t)(cable->hw.formats >>32 ); + }return snd_mask_refine (hw_param_mask (params, rule->var), &m); }
@@ -966,10 +966,10 @@ static int rule_rate(struct snd_pcm_hw_params *params,struct loopback_cable *cable = dpcm->cable;struct snd_interval t; -mutex_lock (&dpcm->loopback->cable_lock); - t.min = cable->hw.rate_min; - t.max = cable->hw.rate_max; -mutex_unlock (&dpcm->loopback->cable_lock); + scoped_guard(mutex, &dpcm->loopback->cable_lock) { + t.min = cable->hw.rate_min; + t.max = cable->hw.rate_max; + } t.openmin = t.openmax =0 ; t.integer =0 ;return snd_interval_refine (hw_param_interval (params, rule->var), &t);
@@ -982,10 +982,10 @@ static int rule_channels(struct snd_pcm_hw_params *params,struct loopback_cable *cable = dpcm->cable;struct snd_interval t; -mutex_lock (&dpcm->loopback->cable_lock); - t.min = cable->hw.channels_min; - t.max = cable->hw.channels_max; -mutex_unlock (&dpcm->loopback->cable_lock); + scoped_guard(mutex, &dpcm->loopback->cable_lock) { + t.min = cable->hw.channels_min; + t.max = cable->hw.channels_max; + } t.openmin = t.openmax =0 ; t.integer =0 ;return snd_interval_refine (hw_param_interval (params, rule->var), &t);
@@ -998,10 +998,10 @@ static int rule_period_bytes(struct snd_pcm_hw_params *params,struct loopback_cable *cable = dpcm->cable;struct snd_interval t; -mutex_lock (&dpcm->loopback->cable_lock); - t.min = cable->hw.period_bytes_min; - t.max = cable->hw.period_bytes_max; -mutex_unlock (&dpcm->loopback->cable_lock); + scoped_guard(mutex, &dpcm->loopback->cable_lock) { + t.min = cable->hw.period_bytes_min; + t.max = cable->hw.period_bytes_max; + } t.openmin =0 ; t.openmax =0 ; t.integer =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1819/3318 ALSA: aloop: Dont constrain playback params in notify mode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henrik Enquist <[email protected]>
[ Upstream commit ded106036984a9dd766e7e1451b02e2d15c81438 ]
With notify enabled (the pcm_notify module parameter or the "PCM Notify" control), the playback side of a cable may change format, rate and channels while a capture is running. loopback_check_format() then stops the capture and notifies the "PCM Slave" controls, so that the capture application can reopen with the new parameters. For this reason loopback_open() still gives a notify mode playback the unconstrained loopback_pcm_hardware.
Since commit 898dfe4687f4 ("ALSA: aloop: Fix racy hw constraints adjustment") the hw rules refine against the shared cable->hw instead of the substream's own runtime->hw. This pins the playback side to the parameters of an open capture whatever the notify setting is. A player probing the device sees only the capture's rate, format and channels, and the format change path in loopback_check_format() can't be reached by a new playback.
Skip the format, rate and channels rules for the playback substream when notify is enabled. Skip the period bytes rule as well: with a sound timer source, params_change() already takes the period size from a notify mode playback, and keeping the old capture's period bytes leaves a playback at another rate with a period that doesn't match the timer. The capture side stays constrained to the cable parameters.
The capture stop this makes reachable again was hardened by commit 826af7fa62e3 ("ALSA: aloop: Fix racy access at PCM trigger") and commit e5c33cdc6f40 ("ALSA: aloop: Fix peer runtime UAF during format-change stop"), which need to be applied first when backporting.
Reproducer, with notify enabled on the cable:
arecord -D hw:Loopback,1,0 -r 44100 -f S32_LE -c 2 /dev/null & aplay -D hw:Loopback,0,0 96k.wav
Before: aplay is forced to 44100 Hz and the capture keeps running.
After: aplay runs at 96000 Hz, the capture is stopped and "PCM Slave Rate" reports 96000.
--- sound/drivers/aloop.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
sound/drivers/aloop.c +20 -0
@@ -944,6 +944,18 @@ static unsigned int get_cable_index(struct snd_pcm_substream *substream)return !substream->stream; } +/* +* In notify mode the playback side may change format, rate, channels and, +* with a sound timer, the period size. A running capture that no longer +* matches is stopped by loopback_check_format(). +* call in loopback->cable_lock +*/ +static bool loopback_playback_unconstrained (struct loopback_pcm *dpcm) +{ +return dpcm->substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && +get_notify (dpcm); +} +static int rule_format (struct snd_pcm_hw_params *params,struct snd_pcm_hw_rule *rule) {
@@ -953,6 +965,8 @@ static int rule_format(struct snd_pcm_hw_params *params,snd_mask_none (&m); scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; m.bits[0 ] = (u_int32_t )cable->hw.formats; m.bits[1 ] = (u_int32_t)(cable->hw.formats >>32 ); }
@@ -967,6 +981,8 @@ static int rule_rate(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.rate_min; t.max = cable->hw.rate_max; }
@@ -983,6 +999,8 @@ static int rule_channels(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.channels_min; t.max = cable->hw.channels_max; }
@@ -999,6 +1017,8 @@ static int rule_period_bytes(struct snd_pcm_hw_params *params,struct snd_interval t; scoped_guard(mutex, &dpcm->loopback->cable_lock) { +if (loopback_playback_unconstrained (dpcm)) +return 0 ; t.min = cable->hw.period_bytes_min; t.max = cable->hw.period_bytes_max; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1820/3318 ALSA: aloop: Update the PCM Slave controls for a matching playback
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Henrik Enquist <[email protected]>
[ Upstream commit c3bde2beacbcb40790f0e3c3f909f9e16bbced9c ]
The "PCM Slave" format, rate, channels and access controls report the parameters of the playback side of a cable. loopback_check_format() updates them when a playback starts, but returns early when a capture is open and its parameters match. The controls then keep the module defaults, or the parameters of an earlier stream.
A playback that joins an open capture with the same parameters is the normal case without notify, where it is constrained to the capture's parameters, and also with notify whenever the player happens to use them. An application that reads the controls to find the playback's parameters, for example to reopen the capture side at the right rate after a restart, then gets the wrong values.
Only skip the capture stop when the parameters match, and update the controls in every case. A value event is still sent only for a control whose value changes.
Reproducer:
arecord -D hw:Loopback,1,0 -r 44100 -f S16_LE -c 2 /dev/null & aplay -D hw:Loopback,0,0 -t raw -r 44100 -f S16_LE -c 2 /dev/zero & amixer -c Loopback cget "iface=PCM,name='PCM Slave Rate',device=1"
Before: the control reports 48000, the module default.
After: it reports 44100.
--- sound/drivers/aloop.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
sound/drivers/aloop.c +7 -4
@@ -346,11 +346,14 @@ static int loopback_check_format(struct loopback_cable *cable, int stream) check = runtime->format != cruntime->format || runtime->rate != cruntime->rate || runtime->channels != cruntime->channels; -if (!check) -return 0 ; -if (stream ==SNDRV_PCM_STREAM_CAPTURE ) +/* +* Matching params also go on to the update below, so that +* the setup controls follow a playback that joins an open +* capture. +*/ +if (check && stream ==SNDRV_PCM_STREAM_CAPTURE )return -EIO ; -else if (cruntime->state ==SNDRV_PCM_STATE_RUNNING ) { +else if (check && cruntime->state ==SNDRV_PCM_STATE_RUNNING ) {/* close must not free the peer runtime below */ atomic_inc (&cable->stop_count); stop_capture = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1821/3318 iommufd/iova_bitmap: Ensure that iova_bitmap_set() handles the full IOVA
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit e21952d72b4740f08a272d694cca223b6b0099ca ]
Generally userspace is going to step the dirty bitmap through the IOVA space. However if the bitmap ends in the middle of a large PTE this is problematic. The first step will clear the dirty bit and report dirty to the end of its bitmap while the second step will see the clear'd dirty and report clean for the start of the bitmap. If it happens this ends up losing dirties.
Further this function is missing bounds checking so if this does happen ther is a good chance it will write memory beyond what the userspace was expecting.
Return an error code if this illegal condition happens.
--- drivers/vfio/iova_bitmap.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/vfio/iova_bitmap.c +16 -2
@@ -113,6 +113,8 @@ struct iova_bitmap {/* length of the IOVA range for the whole bitmap */ size_t length; + +int err; };/*
@@ -381,11 +383,11 @@ int iova_bitmap_for_each(struct iova_bitmap *bitmap, void *opaque, ret = iova_bitmap_advance(bitmap)) { ret =fn (bitmap,iova_bitmap_mapped_iova (bitmap),iova_bitmap_mapped_length (bitmap), opaque); -if (ret) +if (ret || bitmap->err)break ; } -return ret; +return ret ? ret : bitmap->err; }/**
@@ -408,6 +410,18 @@ void iova_bitmap_set(struct iova_bitmap *bitmap, mapped->pgshift) + mapped->pgoff * BITS_PER_BYTE;unsigned long last_page_idx = mapped->npages -1 ; +/* +* If the range cannot be recorded then the system call returns failure. +* This is to prevent loosing dirties if userspace is expecting to step +* the bitmap through the IOVA space. +*/ +if (!length || length > bitmap->length || iova < bitmap->iova || + iova - bitmap->iova > bitmap->length - length) { +if (!bitmap->err) + bitmap->err = -EPROTO ; +return ; + } + do { unsigned int page_idx = cur_bit / BITS_PER_PAGE; unsigned int offset = cur_bit % BITS_PER_PAGE;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1822/3318 virtio_fs: read the vring size under virtio_fs_mutex in ->get_tree
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit e7ccc777a040343b80f95f4cc5c12ce1df3187f4 ]
The vring size was read after virtio_fs_find_instance() had dropped virtio_fs_mutex, so a concurrent virtio_fs_remove() could free the virtqueue first. The reference from the lookup keeps the virtio_fs alive, but not its virtqueues.
Hold the mutex across the lookup and the read.
This issue was found by an in-house static analysis tool.
--- fs/fuse/virtio_fs.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
fs/fuse/virtio_fs.c +11 -10
@@ -265,26 +265,23 @@ static int virtio_fs_add_instance(struct virtio_fs *fs)return 0 ; } -/* Return the virtio_fs with a given tag, or NULL */ +/* Return the virtio_fs with a given tag, or NULL. +* Callers hold virtio_fs_mutex, which also keeps the virtqueues alive. +*/ static struct virtio_fs *virtio_fs_find_instance (const char *tag) {struct virtio_fs *fs; -mutex_lock (&virtio_fs_mutex); +lockdep_assert_held (&virtio_fs_mutex);list_for_each_entry (fs, &virtio_fs_instances, list) {if (strcmp (fs->tag, tag) ==0 ) {kref_get (&fs->refcount); - goto found; +return fs; } } - fs =NULL ;/* not found */ - -found: -mutex_unlock (&virtio_fs_mutex); - -return fs; +return NULL ;/* not found */ }static void virtio_fs_free_devs (struct virtio_fs *fs)
@@ -1488,13 +1485,17 @@ static int virtio_fs_get_tree(struct fs_context *fsc)* in fc->iq->priv. Once fuse_conn is going away, it calls ->put() * to drop the reference to this object. */ +mutex_lock (&virtio_fs_mutex); fs =virtio_fs_find_instance (fsc->source); +if (fs) + virtqueue_size =virtqueue_get_vring_size (fs->vqs[VQ_REQUEST ].vq); +mutex_unlock (&virtio_fs_mutex); +if (!fs) {pr_info ("virtio-fs: tag <%s> not found\n" , fsc->source);return -EINVAL ; } - virtqueue_size =virtqueue_get_vring_size (fs->vqs[VQ_REQUEST ].vq);if (WARN_ON (virtqueue_size <=FUSE_HEADER_OVERHEAD )) goto out_err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1823/3318 crypto: omap-sham - fix crypto engine cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit be51ea091c6563158531e8c74e040552fdb1e28c ]
omap_sham_probe() allocates and starts a crypto engine, but the remove path does not call the matching crypto_engine_exit(). The probe failure path already performs this cleanup.
crypto_engine_alloc_init() creates a kthread worker for processing requests. Without crypto_engine_exit() during driver removal, the worker is left running after the device is removed.
Call crypto_engine_exit() after unregistering the algorithms and before tearing down the remaining request handling resources. This stops the engine and destroys its worker.
This issue was found by manual code inspection.
--- drivers/crypto/omap-sham.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/omap-sham.c +1 -0
@@ -2216,6 +2216,7 @@ static int omap_sham_remove(struct platform_device *pdev) &dd->pdata->algs_info[i].algs_list[j]); dd->pdata->algs_info[i].registered--; } +crypto_engine_exit (dd->engine);tasklet_kill (&dd->done_task);pm_runtime_dont_use_autosuspend (&pdev->dev);pm_runtime_disable (&pdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1824/3318 dcache: report a Tasks-RCU quiescent state in dentry_kill()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit a647a53bc89a046bee4a12a0a5627f2dfaaef807 ]
I am constantly seeing the following warning on Meta's fleet:
INFO: rcu_tasks detected stalls on tasks:
native_queued_spin_lock_slowpath
locked_inode_to_wb_and_lock_list
inode_io_list_del
evict
__dentry_kill
shrink_dentry_list
shrink_dcache_tree
d_invalidate
btrfs_delete_subvolume
btrfs_ioctl_snap_destroy
btrfs_ioctl
do_syscall_64dentry_kill() is the common funnel for dentry teardown: dput(), shrink_dentry_list() and shrink_dcache_tree() all reach it, once per dentry, and its cond_resched() is the only reschedule point on that path.
cond_resched() is not an RCU-tasks quiescent state.
Use cond_resched_tasks_rcu_qs() so the teardown reports an RCU-tasks quiescent state as it proceeds.
--- fs/dcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -1
@@ -625,7 +625,7 @@ static void __dentry_kill(struct dentry *dentry)spin_unlock (&dentry->d_lock);if (likely (can_free))dentry_free (dentry); -cond_resched (); +cond_resched_tasks_rcu_qs (); }static struct dentry *__lock_parent (struct dentry *dentry)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1825/3318 ALSA: usb-audio: rename QUIRK_FLAG_MIXER_MIN_MUTE to QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cryolitia PukNgae <[email protected]>
[ Upstream commit ace1817ab49b3f92b3e965caa63b4a78e69266cd ]
As a preparation of introduction QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE
Also make it printing an info while applying
Stable-dep-of: 874323b68c93 ("ALSA: usb-audio: Add mic resolution quirk for Logitech Webcam C200")
--- sound/usb/mixer_quirks.c | 7 +++++-- sound/usb/quirks.c | 20 ++++++++++---------- sound/usb/usbaudio.h | 4 ++-- 3 files changed, 17 insertions(+), 14 deletions(-)
sound/usb/mixer_quirks.c +5 -2
@@ -3921,9 +3921,12 @@ void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, }/* lowest playback value is muted on some devices */ -if (mixer->chip->quirk_flags &QUIRK_FLAG_MIXER_MIN_MUTE ) -if (strstr (kctl->id.name,"Playback" )) +if (mixer->chip->quirk_flags &QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ) +if (strstr (kctl->id.name,"Playback" )) { +usb_audio_info (mixer->chip, +"applying playback min mute quirk\n" ); cval->min_mute =1 ; + }/* ALSA-ify some Plantronics headset control names */ if (USB_ID_VENDOR(mixer->chip->usb_id) == 0x047f &&
sound/usb/quirks.c +10 -10
@@ -2102,9 +2102,9 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x0556 ,0x0014 ,/* Phoenix Audio TMX320VC */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x0572 ,0x1b08 ,/* Conexant Systems (Rockwell), Inc. */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x0572 ,0x1b09 ,/* Conexant Systems (Rockwell), Inc. */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x05a3 ,0x9420 ,/* ELP HD USB Camera */ QUIRK_FLAG_GET_SAMPLE_RATE ), DEVICE_FLG(0x05a7, 0x1020, /* Bose Companion 5 */
@@ -2154,15 +2154,15 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x0b0e ,0x0349 ,/* Jabra 550a */ QUIRK_FLAG_CTL_MSG_DELAY_1M ),DEVICE_FLG (0x0bda ,0x498a ,/* Realtek Semiconductor Corp. */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x0c45 ,0x6340 ,/* Sonix HD USB Camera */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x0c45 ,0x636b ,/* Microdia JP001 USB Camera */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x0d8c ,0x000c ,/* C-Media */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x0d8c ,0x0014 ,/* C-Media */ -QUIRK_FLAG_CTL_MSG_DELAY_1M |QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_CTL_MSG_DELAY_1M |QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x0ecb ,0x205c ,/* JBL Quantum610 Wireless */ QUIRK_FLAG_FIXED_RATE ), DEVICE_FLG(0x0ecb, 0x2125, /* JBL Quantum650 Wireless */
@@ -2174,7 +2174,7 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x1101 ,0x0003 ,/* Audioengine D1 */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x12d1 ,0x3a07 ,/* Huawei Technologies Co., Ltd. */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x1224 ,0x2a25 ,/* Jieli Technology USB PHY 2.0 */ QUIRK_FLAG_GET_SAMPLE_RATE |QUIRK_FLAG_MIC_RES_16 ), DEVICE_FLG(0x1395, 0x740a, /* Sennheiser DECT */
@@ -2220,7 +2220,7 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x1901 ,0x0191 ,/* GE B850V3 CP2114 audio interface */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x19f7 ,0x0003 ,/* RODE NT-USB */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x19f7 ,0x0035 ,/* RODE NT-USB+ */ QUIRK_FLAG_GET_SAMPLE_RATE ), DEVICE_FLG(0x1bcf, 0x2281, /* HD Webcam */
@@ -2278,7 +2278,7 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x2912 ,0x30c8 ,/* Audioengine D1 */ QUIRK_FLAG_GET_SAMPLE_RATE ),DEVICE_FLG (0x2a70 ,0x1881 ,/* OnePlus Technology (Shenzhen) Co., Ltd. BE02T */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x2b53 ,0x0023 ,/* Fiero SC-01 (firmware v1.0.0 @ 48 kHz) */ QUIRK_FLAG_GENERIC_IMPLICIT_FB ), DEVICE_FLG(0x2b53, 0x0024, /* Fiero SC-01 (firmware v1.0.0 @ 96 kHz) */
@@ -2290,7 +2290,7 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x2d95 ,0x8021 ,/* VIVO USB-C-XE710 HEADSET */ QUIRK_FLAG_CTL_MSG_DELAY_1M ),DEVICE_FLG (0x2d99 ,0x0026 ,/* HECATE G2 GAMING HEADSET */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x2fc6 ,0xf0b7 ,/* iBasso DC07 Pro */ QUIRK_FLAG_CTL_MSG_DELAY_1M ), DEVICE_FLG(0x30be, 0x0101, /* Schiit Hel */
@@ -2298,7 +2298,7 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x3255 ,0x0000 ,/* Luxman D-10X */ QUIRK_FLAG_ITF_USB_DSD_DAC |QUIRK_FLAG_CTL_MSG_DELAY ),DEVICE_FLG (0x339b ,0x3a07 ,/* Synaptics HONOR USB-C HEADSET */ -QUIRK_FLAG_MIXER_MIN_MUTE ), +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x413c ,0xa506 ,/* Dell AE515 sound bar */ QUIRK_FLAG_GET_SAMPLE_RATE ), DEVICE_FLG(0x534d, 0x0021, /* MacroSilicon MS2100/MS2106 */
sound/usb/usbaudio.h +2 -2
@@ -184,7 +184,7 @@ extern bool snd_usb_skip_validation;* for the given endpoint. * QUIRK_FLAG_MIC_RES_16 and QUIRK_FLAG_MIC_RES_384 * Set the fixed resolution for Mic Capture Volume (mostly for webcams) -* QUIRK_FLAG_MIXER_MIN_MUTE +* QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE * Set minimum volume control value as mute for devices where the lowest * playback value represents muted state instead of minimum audible volume */
@@ -213,6 +213,6 @@ extern bool snd_usb_skip_validation;#define QUIRK_FLAG_FIXED_RATE (1U << 21)#define QUIRK_FLAG_MIC_RES_16 (1U << 22)#define QUIRK_FLAG_MIC_RES_384 (1U << 23) -#define QUIRK_FLAG_MIXER_MIN_MUTE (1U << 24) +#define QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE (1U << 24)#endif /* __USBAUDIO_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1826/3318 ALSA: usb-audio: add volume quirks for MS LifeChat LX-3000
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit 9af61fc91486c7ba93cf1ec3bd381978cac8308c ]
ID 045e:070f Microsoft Corp. LifeChat LX-3000 Headset has muted minimum Speaker Playback Volume, and 4 amixer steps were observed to produce 1 actual volume step.
Apply min_mute quirk and correct res=48 -> 4*48.
Tested with the device.
Stable-dep-of: 874323b68c93 ("ALSA: usb-audio: Add mic resolution quirk for Logitech Webcam C200")
--- sound/usb/mixer.c | 8 ++++++++ sound/usb/quirks.c | 2 ++ 2 files changed, 10 insertions(+)
sound/usb/mixer.c +8 -0
@@ -1156,6 +1156,14 @@ static void volume_control_quirks(struct usb_mixer_elem_info *cval, }break ; +case USB_ID (0x045e ,0x070f ):/* MS LifeChat LX-3000 Headset */ +if (!strcmp (kctl->id.name,"Speaker Playback Volume" )) { +usb_audio_info (chip, +"set volume quirk for MS LifeChat LX-3000\n" ); + cval->res =192 ; + } +break ; +case USB_ID (0x0471 ,0x0101 ):case USB_ID (0x0471 ,0x0104 ):case USB_ID (0x0471 ,0x0105 ):
sound/usb/quirks.c +2 -0
@@ -2058,6 +2058,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {DEVICE_FLG (0x045e ,0x083c ,/* MS USB Link headset */ QUIRK_FLAG_GET_SAMPLE_RATE |QUIRK_FLAG_CTL_MSG_DELAY |QUIRK_FLAG_DISABLE_AUTOSUSPEND ), +DEVICE_FLG (0x045e ,0x070f ,/* MS LifeChat LX-3000 Headset */ +QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ),DEVICE_FLG (0x046d ,0x0807 ,/* Logitech Webcam C500 */ QUIRK_FLAG_CTL_MSG_DELAY_1M |QUIRK_FLAG_MIC_RES_384 ), DEVICE_FLG(0x046d, 0x0808, /* Logitech Webcam C600 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1827/3318 ALSA: usb-audio: Add mic resolution quirk for Logitech Webcam C200
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Kaloudoff <[email protected]>
[ Upstream commit 874323b68c93c6808e034dc0113681e822e6fb42 ]
The C200 (046d:0802) reports a mic capture volume range of 1536..7680 with a resolution of 1 (6144 steps), triggering "Warning! Unlikely big volume step count (=6144), linear volume or wrong cval->res?" at probe and exposing a uselessly fine-grained mixer control. This is the same firmware behavior as the other UVC-era Logitech webcams already carrying QUIRK_FLAG_MIC_RES_384 (C500, C600, C210, C270, C310, C510, C525, ...), so apply the same
quirk: CTL_MSG_DELAY_1M (which the Logitech VENDOR_FLG would provide if the device-specific entry did not short-circuit the lookup) plus MIC_RES_384.
Verified on real hardware: with the quirk the warning disappears and the driver logs "set resolution quirk: cval->res = 384".
--- sound/usb/quirks.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/quirks.c +2 -0
@@ -2060,6 +2060,8 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = { QUIRK_FLAG_DISABLE_AUTOSUSPEND),DEVICE_FLG (0x045e ,0x070f ,/* MS LifeChat LX-3000 Headset */ QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE ), +DEVICE_FLG (0x046d ,0x0802 ,/* Logitech Webcam C200 */ +QUIRK_FLAG_CTL_MSG_DELAY_1M |QUIRK_FLAG_MIC_RES_384 ),DEVICE_FLG (0x046d ,0x0807 ,/* Logitech Webcam C500 */ QUIRK_FLAG_CTL_MSG_DELAY_1M |QUIRK_FLAG_MIC_RES_384 ), DEVICE_FLG(0x046d, 0x0808, /* Logitech Webcam C600 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1828/3318 power: supply: ltc2941: Fix of_node reference leak in ltc294x_i2c_probe()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 09a29213bf15630e85a375478832b074b2cfc5c8 ]
ltc294x_i2c_probe() takes a reference on the device node with of_node_get(), but never drops it, so the reference leaks on every return path, including the success path.
The node is only used to read the battery properties and to set info->supply_desc.name, so release it after its last use and also on the lltc,resistor-sense error path.
--- drivers/power/supply/ltc2941-battery-gauge.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/power/supply/ltc2941-battery-gauge.c +5 -1
@@ -464,9 +464,11 @@ static int ltc294x_i2c_probe(struct i2c_client *client)/* r_sense can be negative, when sense+ is connected to the battery * instead of the sense-. This results in reversed measurements. */ ret =of_property_read_u32 (np,"lltc,resistor-sense" , &r_sense); -if (ret <0 ) +if (ret <0 ) { +of_node_put (np);return dev_err_probe (&client->dev, ret,"Could not find lltc,resistor-sense in devicetree\n" ); + } info->r_sense = r_sense; ret = of_property_read_u32(np, "lltc,prescaler-exponent",
@@ -477,6 +479,8 @@ static int ltc294x_i2c_probe(struct i2c_client *client) prescaler_exp =LTC2941_MAX_PRESCALER_EXP ; } +of_node_put (np); +if (info->id ==LTC2943_ID ) {if (prescaler_exp >LTC2943_MAX_PRESCALER_EXP ) prescaler_exp =LTC2943_MAX_PRESCALER_EXP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1829/3318 ata: ahci: print the lpm policy on boot
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit affccb16c117d188eb09495cbdea149cecbf00b9 ]
The target LPM policy can be set using either a Kconfig or a kernel module parameter.
However, if the board type is set to anything but board_ahci_low_power, then the LPM policy will overridden and set to ATA_LPM_UNKNOWN.
Additionally, if the default suspend is suspend to idle, depending on the hardware capabilities of the HBA, ahci_update_initial_lpm_policy() might override the LPM policy to either ATA_LPM_MIN_POWER_WITH_PARTIAL or ATA_LPM_MIN_POWER.
All this means that it is very hard to know which LPM policy a user will actually be using on a given system.
In order to make it easier to debug LPM related issues, print the LPM policy on boot.
One common LPM related issue is that the device fails to link up. Because of that, we cannot add this print to ata_dev_configure(), as that function is only called after a successful link up. Instead, add the info using ata_port_desc(), with the help of a new ata_port_desc_misc() helper. The port description is printed once per port during boot.
Before changes:
ata1: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780100 irq 170
ata2: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780180 irq 170
After changes:
ata1: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780100 irq 170 lpm-pol 4
ata2: SATA max UDMA/133 abar m524288@0xa5780000 port 0xa5780180 irq 170 lpm-pol 4
Stable-dep-of: 34a4a34431ed ("ata: libahci: Free the IRQs when activating a multi-IRQ host fails")
--- drivers/ata/libahci.c | 2 +- drivers/ata/libata-core.c | 2 +- drivers/ata/libata-sff.c | 10 +++++----- drivers/ata/pata_cs5520.c | 2 +- include/linux/libata.h | 5 +++++ 5 files changed, 13 insertions(+), 8 deletions(-)
drivers/ata/libahci.c +1 -1
@@ -2736,7 +2736,7 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host,if (rc)return rc; -ata_port_desc (host->ports[i],"irq %d" , irq); +ata_port_desc_misc (host->ports[i], irq); }return ata_host_register (host, sht);
drivers/ata/libata-core.c +1 -1
@@ -6134,7 +6134,7 @@ int ata_host_activate(struct ata_host *host, int irq,return rc;for (i =0 ; i < host->n_ports; i++) -ata_port_desc (host->ports[i],"irq %d" , irq); +ata_port_desc_misc (host->ports[i], irq); rc =ata_host_register (host, sht);/* if failed, just free the IRQ and leave ports alone */
drivers/ata/libata-sff.c +5 -5
@@ -2318,7 +2318,7 @@ int ata_pci_sff_activate_host(struct ata_host *host,for (i =0 ; i <2 ; i++) {if (ata_port_is_dummy (host->ports[i]))continue ; -ata_port_desc (host->ports[i],"irq %d" , pdev->irq); +ata_port_desc_misc (host->ports[i], pdev->irq); } }else if (legacy_mode) {if (!ata_port_is_dummy (host->ports[0 ])) {
@@ -2328,8 +2328,8 @@ int ata_pci_sff_activate_host(struct ata_host *host,if (rc) goto out; -ata_port_desc (host->ports[0 ],"irq %d" , -ATA_PRIMARY_IRQ (pdev)); +ata_port_desc_misc (host->ports[0 ], +ATA_PRIMARY_IRQ (pdev)); }if (!ata_port_is_dummy (host->ports[1 ])) {
@@ -2339,8 +2339,8 @@ int ata_pci_sff_activate_host(struct ata_host *host,if (rc) goto out; -ata_port_desc (host->ports[1 ],"irq %d" , -ATA_SECONDARY_IRQ (pdev)); +ata_port_desc_misc (host->ports[1 ], +ATA_SECONDARY_IRQ (pdev)); } }
drivers/ata/pata_cs5520.c +1 -1
@@ -212,7 +212,7 @@ static int cs5520_init_one(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; -ata_port_desc (ap,"irq %d" , irq[i]); +ata_port_desc_misc (ap, irq[i]); }return ata_host_register (host, &cs5520_sht);
include/linux/libata.h +5 -0
@@ -1562,6 +1562,11 @@ void ata_port_desc(struct ata_port *ap, const char *fmt, ...);extern void ata_port_pbar_desc (struct ata_port *ap,int bar,ssize_t offset,const char *name);#endif +static inline void ata_port_desc_misc (struct ata_port *ap,int irq) +{ +ata_port_desc (ap,"irq %d" , irq); +ata_port_desc (ap,"lpm-pol %d" , ap->target_lpm_policy); +}static inline bool ata_tag_internal (unsigned int tag) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1830/3318 ata: libahci: Free the IRQs when activating a multi-IRQ host fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 34a4a34431ed81d85d14f8fb8035e5a25214ad39 ]
ahci_host_activate_multi_irqs() requests one IRQ per port, but it does not free them when requesting one of them, or when registering the host, fails. The IRQs are only freed by the driver core, when it releases the devres of the device after probe() has returned, while the caller of ahci_host_activate() releases the resources of the host in its probe() error path, e.g. ahci_probe() disables the clocks, regulators, resets and PHYs of the host. An IRQ handler running in that window would access the MMIO of a host which is no longer clocked.
ahci_host_activate_multi_irqs() did free the IRQs until commit 0a142b26921c ("ahci: cleanup ahci_host_activate_multi_irqs"), which removed the explicit free because devm makes it unnecessary. That is true for freeing the IRQs as such, but not for the window described above:
devres is only released after probe() has returned, i.e. after the error path of the caller has released the resources of the host.
Note that this window cannot be hit with the current users: the only user of AHCI_HFLAG_MULTI_MSI is the AHCI PCI driver, which does not release any resource in its probe() error path, and the ports of the host are still frozen, i.e. their interrupts are masked, when ata_host_register() fails.
Free the IRQs explicitly again, like ata_host_activate() does, so that the IRQ handlers cannot run once ahci_host_activate() has failed.
--- drivers/ata/libahci.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
drivers/ata/libahci.c +24 -2
@@ -2735,11 +2735,33 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, 0, pp->irq_desc, host->ports[i]);if (rc) -return rc; + goto free_irqs;ata_port_desc_misc (host->ports[i], irq); } -return ata_host_register (host, sht); + rc =ata_host_register (host, sht); +if (rc) + goto free_irqs; + +return 0 ; + +free_irqs: +/* +* Free the IRQs which have been requested, so that the handlers can no +* longer access the MMIO of the host once we return, e.g. after the +* caller has disabled the clocks of the host. +*/ +while (--i >=0 ) { +struct ahci_port_priv *pp = host->ports[i]->private_data; + +if (!pp) +continue ; + +devm_free_irq (host->dev, hpriv->get_irq_vector (host, i), + host->ports[i]); + } + +return rc; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1831/3318 wifi: mt76: mt7615: restore DBDC state after ext PHY failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 7907d5270dc5c13b6a95754c08a77d5b06bbc786 ]
mt7615_register_ext_phy() limits the primary PHY to DBDC capabilities before allocating and registering the secondary PHY. If allocation, EEPROM override, or PHY registration fails, it returns without restoring the primary PHY capabilities. The EEPROM override failure also leaks the newly allocated ieee80211_hw.
Route all failures through common labels that free the secondary hardware when it was allocated and restore the primary PHY capabilities.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/net/wireless/mediatek/mt76/mt7615/init.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/init.c +12 -3
@@ -545,8 +545,10 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev)mt7615_cap_dbdc_enable (dev); mphy =mt76_alloc_phy (&dev->mt76,sizeof (*phy), &mt7615_ops,MT_BAND1 ); -if (!mphy) -return -ENOMEM ; +if (!mphy) { + ret = -ENOMEM ; + goto error; + } phy = mphy->priv; phy->dev = dev;
@@ -591,7 +593,14 @@ int mt7615_register_ext_phy(struct mt7615_dev *dev) ret =mt76_register_phy (mphy, true, mt76_rates,ARRAY_SIZE (mt76_rates));if (ret) -ieee80211_free_hw (mphy->hw); + goto error_free_hw; + +return 0 ; + +error_free_hw: +ieee80211_free_hw (mphy->hw); +error: +mt7615_cap_dbdc_disable (dev);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1832/3318 Input: xpad - add GameSir Nova Lite support
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Francesco Orlando <[email protected]>
[ Upstream commit 2e6f2e5799f328ca0879dad14d7f3709c7f7496b ]
Add vendor and product ID for GameSir Nova Lite (0x3537:0x1040) in XInput mode to enable force feedback rumble support.
--- drivers/input/joystick/xpad.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/joystick/xpad.c +1 -0
@@ -431,6 +431,7 @@ static const struct xpad_device { { 0x3537, 0x1004, "GameSir T4 Kaleid", 0, XTYPE_XBOX360 }, { 0x3537, 0x100f, "GameSir Nova 2 Lite", 0, XTYPE_XBOX360 }, { 0x3537, 0x1010, "GameSir G7 SE", 0, XTYPE_XBOXONE }, + { 0x3537, 0x1040, "GameSir Nova Lite", 0, XTYPE_XBOX360 }, { 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX }, { 0x413d, 0x2104, "Black Shark Green Ghost Gamepad", 0, XTYPE_XBOX360 }, { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1833/3318 power: supply: core: remove opencoded string_lower()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 0ce51459c8353b2b18ad3a430dbebf29af8b579c ]
string_lower from string_helpers.h can be used to modify the string in-place. Use it to get rid of the custom str_to_lower().
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_sysfs.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/power/supply/power_supply_sysfs.c +3 -9
@@ -15,6 +15,7 @@#include <linux/power_supply.h> #include <linux/slab.h> #include <linux/stat.h> +#include <linux/string_helpers.h> #include "power_supply.h"
@@ -398,14 +399,6 @@ static const struct attribute_group *power_supply_attr_groups[] = { NULL, }; -static void str_to_lower (char *str) -{ -while (*str) { - *str =tolower (*str); - str++; - } -} -void power_supply_init_attrs (struct device_type *dev_type) {int i;
@@ -420,7 +413,8 @@ void power_supply_init_attrs(struct device_type *dev_type) __func__, i);sprintf (power_supply_attrs[i].attr_name,"_err_%d" , i); }else { -str_to_lower (power_supply_attrs[i].attr_name); +string_lower (power_supply_attrs[i].attr_name, + power_supply_attrs[i].attr_name); } attr = &power_supply_attrs[i].dev_attr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1834/3318 power: supply: core: make power_supply_class constant
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo B. Marliere <[email protected]>
[ Upstream commit 71c2cc5cbf686c2397f43cbcb51a31589bdcee7b ]
Since commit 43a7206b0963 ("driver core: class: make class_register() take a const *"), the driver core allows for struct class to be in read-only memory, so move the power_supply_class structure to be declared at build time placing it into read-only memory, instead of having to be dynamically allocated at boot time.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/ab8500_btemp.c | 2 +- drivers/power/supply/ab8500_chargalg.c | 2 +- drivers/power/supply/ab8500_charger.c | 2 +- drivers/power/supply/ab8500_fg.c | 2 +- drivers/power/supply/apm_power.c | 2 +- drivers/power/supply/power_supply_core.c | 39 +++++++++++++----------- include/linux/power_supply.h | 2 +- 7 files changed, 27 insertions(+), 24 deletions(-)
drivers/power/supply/ab8500_btemp.c +1 -1
@@ -617,7 +617,7 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)*/ static void ab8500_btemp_external_power_changed (struct power_supply *psy) { -class_for_each_device (power_supply_class,NULL , psy, +class_for_each_device (&power_supply_class,NULL , psy, ab8500_btemp_get_ext_psy_data); }
drivers/power/supply/ab8500_chargalg.c +1 -1
@@ -1231,7 +1231,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)int ret;/* Collect data from all power_supply class devices */ -class_for_each_device (power_supply_class,NULL , +class_for_each_device (&power_supply_class,NULL , di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);ab8500_chargalg_end_of_charge (di);
drivers/power/supply/ab8500_charger.c +1 -1
@@ -1949,7 +1949,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)struct ab8500_charger *di =container_of (work, struct ab8500_charger, check_vbat_work.work); -class_for_each_device (power_supply_class,NULL , +class_for_each_device (&power_supply_class,NULL , &di->usb_chg, ab8500_charger_get_ext_psy_data);/* First run old_vbat is 0. */
drivers/power/supply/ab8500_fg.c +1 -1
@@ -2408,7 +2408,7 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)*/ static void ab8500_fg_external_power_changed (struct power_supply *psy) { -class_for_each_device (power_supply_class,NULL , psy, +class_for_each_device (&power_supply_class,NULL , psy, ab8500_fg_get_ext_psy_data); }
drivers/power/supply/apm_power.c +1 -1
@@ -79,7 +79,7 @@ static void find_main_battery(void) main_battery =NULL ; bp.main = main_battery; - error =class_for_each_device (power_supply_class,NULL , &bp, + error =class_for_each_device (&power_supply_class,NULL , &bp, __find_main_battery);if (error) { main_battery = bp.main;
drivers/power/supply/power_supply_core.c +21 -18
@@ -26,7 +26,10 @@#include "samsung-sdi-battery.h" /* exported for the APM Power driver, APM emulation */ -struct class *power_supply_class; +const struct class power_supply_class = { + .name ="power_supply" , + .dev_uevent = power_supply_uevent, +};EXPORT_SYMBOL_GPL (power_supply_class);BLOCKING_NOTIFIER_HEAD (power_supply_notifier);
@@ -94,7 +97,7 @@ static void power_supply_changed_work(struct work_struct *work)if (likely (psy->changed)) { psy->changed = false;spin_unlock_irqrestore (&psy->changed_lock, flags); -class_for_each_device (power_supply_class,NULL , psy, +class_for_each_device (&power_supply_class,NULL , psy, __power_supply_changed_work);power_supply_update_leds (psy); blocking_notifier_call_chain(&power_supply_notifier,
@@ -188,7 +191,7 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) {int error; - error =class_for_each_device (power_supply_class,NULL , psy, + error =class_for_each_device (&power_supply_class,NULL , psy, __power_supply_populate_supplied_from);dev_dbg (&psy->dev,"%s %d\n" , __func__, error);
@@ -223,8 +226,8 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)* We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if * it returned 0, or error as returned by it. */ - error =class_for_each_device (power_supply_class,NULL , supply_node, - __power_supply_find_supply_from_node); + error =class_for_each_device (&power_supply_class,NULL , supply_node, + __power_supply_find_supply_from_node);return error ? (error ==1 ?0 : error) : -EPROBE_DEFER ; }
@@ -325,7 +328,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)struct psy_am_i_supplied_data data = { psy,0 };int error; - error =class_for_each_device (power_supply_class,NULL , &data, + error =class_for_each_device (&power_supply_class,NULL , &data, __power_supply_am_i_supplied);dev_dbg (&psy->dev,"%s count %u err %d\n" , __func__, data.count, error);
@@ -361,7 +364,7 @@ int power_supply_is_system_supplied(void)int error;unsigned int count =0 ; - error =class_for_each_device (power_supply_class,NULL , &count, + error =class_for_each_device (&power_supply_class,NULL , &count, __power_supply_is_system_supplied);/*
@@ -408,7 +411,7 @@ int power_supply_get_property_from_supplier(struct power_supply *psy,* This function is not intended for use with a supply with multiple * suppliers, we simply pick the first supply to report the psp. */ - ret =class_for_each_device (power_supply_class,NULL , &data, + ret =class_for_each_device (&power_supply_class,NULL , &data, __power_supply_get_supplier_property);if (ret <0 )return ret;
@@ -454,8 +457,8 @@ static int power_supply_match_device_by_name(struct device *dev, const void *datstruct power_supply *power_supply_get_by_name (const char *name) {struct power_supply *psy =NULL ; -struct device *dev =class_find_device (power_supply_class,NULL , name, - power_supply_match_device_by_name); +struct device *dev =class_find_device (&power_supply_class,NULL , name, + power_supply_match_device_by_name);if (dev) { psy =dev_get_drvdata (dev);
@@ -509,8 +512,8 @@ struct power_supply *power_supply_get_by_phandle(struct device_node *np,if (!power_supply_np)return ERR_PTR (-ENODEV ); - dev =class_find_device (power_supply_class,NULL , power_supply_np, - power_supply_match_device_node); + dev =class_find_device (&power_supply_class,NULL , power_supply_np, + power_supply_match_device_node);of_node_put (power_supply_np);
@@ -1362,7 +1365,7 @@ __power_supply_register(struct device *parent,device_initialize (dev); - dev->class = power_supply_class; + dev->class = &power_supply_class; dev->type = &power_supply_dev_type; dev->parent = parent; dev->release = power_supply_dev_release;
@@ -1609,12 +1612,12 @@ EXPORT_SYMBOL_GPL(power_supply_get_drvdata);static int __init power_supply_class_init (void ) { - power_supply_class =class_create ("power_supply" ); +int err; -if (IS_ERR (power_supply_class)) -return PTR_ERR (power_supply_class); + err =class_register (&power_supply_class); +if (err) +return err; - power_supply_class->dev_uevent = power_supply_uevent;power_supply_init_attrs (&power_supply_dev_type);return 0 ;
@@ -1622,7 +1625,7 @@ static int __init power_supply_class_init(void) static void __exit power_supply_class_exit(void) { -class_destroy (power_supply_class); +class_unregister (&power_supply_class); }subsys_initcall (power_supply_class_init);
include/linux/power_supply.h +1 -1
@@ -896,7 +896,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);extern void *power_supply_get_drvdata (struct power_supply *psy);/* For APM emulation, think legacy userspace. */ -extern struct class *power_supply_class; +extern const struct class power_supply_class;static inline bool power_supply_is_amp_property (enum power_supply_property psp) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1835/3318 power: supply: core: add power_supply_for_each_device()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 68ade0976df7979eac5f1d46320ff798f5043af6 ]
Introduce power_supply_for_each_device(), which is a wrapper for class_for_each_device() using the power_supply_class and going through all devices.
This allows making the power_supply_class itself a local variable, so that drivers cannot mess with it and simplifies the code slightly.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/ab8500_btemp.c | 3 +-- drivers/power/supply/ab8500_chargalg.c | 3 +-- drivers/power/supply/ab8500_charger.c | 3 +-- drivers/power/supply/ab8500_fg.c | 3 +-- drivers/power/supply/apm_power.c | 3 +-- drivers/power/supply/power_supply_core.c | 34 +++++++++++------------- include/linux/power_supply.h | 3 +-- 7 files changed, 22 insertions(+), 30 deletions(-)
drivers/power/supply/ab8500_btemp.c +1 -2
@@ -617,8 +617,7 @@ static int ab8500_btemp_get_ext_psy_data(struct device *dev, void *data)*/ static void ab8500_btemp_external_power_changed (struct power_supply *psy) { -class_for_each_device (&power_supply_class,NULL , psy, - ab8500_btemp_get_ext_psy_data); +power_supply_for_each_device (psy, ab8500_btemp_get_ext_psy_data); }/* ab8500 btemp driver interrupts and their respective isr */
drivers/power/supply/ab8500_chargalg.c +1 -2
@@ -1231,8 +1231,7 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di)int ret;/* Collect data from all power_supply class devices */ -class_for_each_device (&power_supply_class,NULL , - di->chargalg_psy, ab8500_chargalg_get_ext_psy_data); +power_supply_for_each_device (di->chargalg_psy, ab8500_chargalg_get_ext_psy_data);ab8500_chargalg_end_of_charge (di);ab8500_chargalg_check_temp (di);
drivers/power/supply/ab8500_charger.c +1 -2
@@ -1949,8 +1949,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work)struct ab8500_charger *di =container_of (work, struct ab8500_charger, check_vbat_work.work); -class_for_each_device (&power_supply_class,NULL , - &di->usb_chg, ab8500_charger_get_ext_psy_data); +power_supply_for_each_device (&di->usb_chg, ab8500_charger_get_ext_psy_data);/* First run old_vbat is 0. */ if (di->old_vbat ==0 )
drivers/power/supply/ab8500_fg.c +1 -2
@@ -2408,8 +2408,7 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di)*/ static void ab8500_fg_external_power_changed (struct power_supply *psy) { -class_for_each_device (&power_supply_class,NULL , psy, - ab8500_fg_get_ext_psy_data); +power_supply_for_each_device (psy, ab8500_fg_get_ext_psy_data); }/**
drivers/power/supply/apm_power.c +1 -2
@@ -79,8 +79,7 @@ static void find_main_battery(void) main_battery =NULL ; bp.main = main_battery; - error =class_for_each_device (&power_supply_class,NULL , &bp, - __find_main_battery); + error =power_supply_for_each_device (&bp, __find_main_battery);if (error) { main_battery = bp.main;return ;
drivers/power/supply/power_supply_core.c +16 -18
@@ -25,12 +25,10 @@#include "power_supply.h" #include "samsung-sdi-battery.h" -/* exported for the APM Power driver, APM emulation */ -const struct class power_supply_class = { +static const struct class power_supply_class = { .name ="power_supply" , .dev_uevent = power_supply_uevent, }; -EXPORT_SYMBOL_GPL (power_supply_class);BLOCKING_NOTIFIER_HEAD (power_supply_notifier);EXPORT_SYMBOL_GPL (power_supply_notifier);
@@ -97,8 +95,7 @@ static void power_supply_changed_work(struct work_struct *work)if (likely (psy->changed)) { psy->changed = false;spin_unlock_irqrestore (&psy->changed_lock, flags); -class_for_each_device (&power_supply_class,NULL , psy, - __power_supply_changed_work); +power_supply_for_each_device (psy, __power_supply_changed_work);power_supply_update_leds (psy);blocking_notifier_call_chain (&power_supply_notifier,PSY_EVENT_PROP_CHANGED , psy);
@@ -116,6 +113,12 @@ static void power_supply_changed_work(struct work_struct *work)spin_unlock_irqrestore (&psy->changed_lock, flags); } +int power_supply_for_each_device (void *data,int (*fn)(struct device *dev,void *data)) +{ +return class_for_each_device (&power_supply_class,NULL , data, fn); +} +EXPORT_SYMBOL_GPL (power_supply_for_each_device); +void power_supply_changed (struct power_supply *psy) {unsigned long flags;
@@ -191,8 +194,7 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) {int error; - error =class_for_each_device (&power_supply_class,NULL , psy, - __power_supply_populate_supplied_from); + error =power_supply_for_each_device (psy, __power_supply_populate_supplied_from);dev_dbg (&psy->dev,"%s %d\n" , __func__, error);
@@ -205,7 +207,7 @@ static int __power_supply_find_supply_from_node(struct device *dev,struct device_node *np = data;struct power_supply *epsy =dev_get_drvdata (dev); -/* returning non-zero breaks out of class_for_each_device loop */ +/* returning non-zero breaks out of power_supply_for_each_device loop */ if (epsy->of_node == np)return 1 ;
@@ -217,17 +219,16 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)int error;/* -* class_for_each_device() either returns its own errors or values +* power_supply_for_each_device() either returns its own errors or values * returned by __power_supply_find_supply_from_node(). * * __power_supply_find_supply_from_node() will return 0 (no match) * or 1 (match). * -* We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if +* We return 0 if power_supply_for_each_device() returned 1, -EPROBE_DEFER if * it returned 0, or error as returned by it. */ - error =class_for_each_device (&power_supply_class,NULL , supply_node, - __power_supply_find_supply_from_node); + error =power_supply_for_each_device (supply_node, __power_supply_find_supply_from_node);return error ? (error ==1 ?0 : error) : -EPROBE_DEFER ; }
@@ -328,8 +329,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)struct psy_am_i_supplied_data data = { psy,0 };int error; - error =class_for_each_device (&power_supply_class,NULL , &data, - __power_supply_am_i_supplied); + error =power_supply_for_each_device (&data, __power_supply_am_i_supplied);dev_dbg (&psy->dev,"%s count %u err %d\n" , __func__, data.count, error);
@@ -364,8 +364,7 @@ int power_supply_is_system_supplied(void)int error;unsigned int count =0 ; - error =class_for_each_device (&power_supply_class,NULL , &count, - __power_supply_is_system_supplied); + error =power_supply_for_each_device (&count, __power_supply_is_system_supplied);/* * If no system scope power class device was found at all, most probably we
@@ -411,8 +410,7 @@ int power_supply_get_property_from_supplier(struct power_supply *psy,* This function is not intended for use with a supply with multiple * suppliers, we simply pick the first supply to report the psp. */ - ret =class_for_each_device (&power_supply_class,NULL , &data, - __power_supply_get_supplier_property); + ret =power_supply_for_each_device (&data, __power_supply_get_supplier_property);if (ret <0 )return ret;if (ret ==0 )
include/linux/power_supply.h +1 -2
@@ -895,8 +895,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);#define to_power_supply (device) container_of(device, struct power_supply, dev)extern void *power_supply_get_drvdata (struct power_supply *psy); -/* For APM emulation, think legacy userspace. */ -extern const struct class power_supply_class; +extern int power_supply_for_each_device (void *data,int (*fn)(struct device *dev,void *data));static inline bool power_supply_is_amp_property (enum power_supply_property psp) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1836/3318 power: supply: core: introduce power_supply_for_each_psy()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 9029409d1a250da19f1086ab1113752411c5163d ]
All existing callers of power_supply_for_each_device() want to iterate over 'struct power_supply', not 'struct device'.
The power_supply_for_each_device() forces each caller to duplicate the logic to go from one to the other.
Introduce power_supply_for_each_psy() to simplify the callers.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 24 ++++++++++++++++++++++++ include/linux/power_supply.h | 1 + 2 files changed, 25 insertions(+)
drivers/power/supply/power_supply_core.c +24 -0
@@ -119,6 +119,30 @@ int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void }EXPORT_SYMBOL_GPL (power_supply_for_each_device); +struct psy_for_each_psy_cb_data { +int (*fn)(struct power_supply *psy,void *data); +void *data; +}; + +static int psy_for_each_psy_cb (struct device *dev,void *data) +{ +struct psy_for_each_psy_cb_data *cb_data = data; +struct power_supply *psy =dev_get_drvdata (dev); + +return cb_data->fn (psy, cb_data->data); +} + +int power_supply_for_each_psy (void *data,int (*fn)(struct power_supply *psy,void *data)) +{ +struct psy_for_each_psy_cb_data cb_data = { + .fn = fn, + .data = data, + }; + +return power_supply_for_each_device (&cb_data, psy_for_each_psy_cb); +} +EXPORT_SYMBOL_GPL (power_supply_for_each_psy); +void power_supply_changed (struct power_supply *psy) {unsigned long flags;
include/linux/power_supply.h +1 -0
@@ -896,6 +896,7 @@ extern int power_supply_powers(struct power_supply *psy, struct device *dev);extern void *power_supply_get_drvdata (struct power_supply *psy);extern int power_supply_for_each_device (void *data,int (*fn)(struct device *dev,void *data)); +extern int power_supply_for_each_psy (void *data,int (*fn)(struct power_supply *psy,void *data));static inline bool power_supply_is_amp_property (enum power_supply_property psp) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1837/3318 power: supply: core: use power_supply_for_each_psy()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Weißschuh <[email protected]>
[ Upstream commit 68abaf7323ae857db7ec56a174b7bbf5fc687d47 ]
Simplify the callbacks by removing the need to convert a 'struct device' into a 'struct power_supply'.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 36 ++++++++++-------------- 1 file changed, 15 insertions(+), 21 deletions(-)
drivers/power/supply/power_supply_core.c +15 -21
@@ -63,10 +63,9 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,return false; } -static int __power_supply_changed_work (struct device *dev,void *data) +static int __power_supply_changed_work (struct power_supply *pst,void *data) {struct power_supply *psy = data; -struct power_supply *pst =dev_get_drvdata (dev);if (__power_supply_is_supplied_by (psy, pst)) {if (pst->desc->external_power_changed)
@@ -95,7 +94,7 @@ static void power_supply_changed_work(struct work_struct *work)if (likely (psy->changed)) { psy->changed = false;spin_unlock_irqrestore (&psy->changed_lock, flags); -power_supply_for_each_device (psy, __power_supply_changed_work); +power_supply_for_each_psy (psy, __power_supply_changed_work);power_supply_update_leds (psy);blocking_notifier_call_chain (&power_supply_notifier,PSY_EVENT_PROP_CHANGED , psy);
@@ -187,11 +186,10 @@ static void power_supply_deferred_register_work(struct work_struct *work) }#ifdef CONFIG_OF -static int __power_supply_populate_supplied_from (struct device *dev, +static int __power_supply_populate_supplied_from (struct power_supply *epsy,void *data) {struct power_supply *psy = data; -struct power_supply *epsy =dev_get_drvdata (dev);struct device_node *np;int i =0 ;
@@ -218,20 +216,19 @@ static int power_supply_populate_supplied_from(struct power_supply *psy) {int error; - error =power_supply_for_each_device (psy, __power_supply_populate_supplied_from); + error =power_supply_for_each_psy (psy, __power_supply_populate_supplied_from);dev_dbg (&psy->dev,"%s %d\n" , __func__, error);return error; } -static int __power_supply_find_supply_from_node (struct device *dev, +static int __power_supply_find_supply_from_node (struct power_supply *epsy,void *data) {struct device_node *np = data; -struct power_supply *epsy =dev_get_drvdata (dev); -/* returning non-zero breaks out of power_supply_for_each_device loop */ +/* returning non-zero breaks out of power_supply_for_each_psy loop */ if (epsy->of_node == np)return 1 ;
@@ -243,16 +240,16 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)int error;/* -* power_supply_for_each_device() either returns its own errors or values +* power_supply_for_each_psy() either returns its own errors or values * returned by __power_supply_find_supply_from_node(). * * __power_supply_find_supply_from_node() will return 0 (no match) * or 1 (match). * -* We return 0 if power_supply_for_each_device() returned 1, -EPROBE_DEFER if +* We return 0 if power_supply_for_each_psy() returned 1, -EPROBE_DEFER if * it returned 0, or error as returned by it. */ - error =power_supply_for_each_device (supply_node, __power_supply_find_supply_from_node); + error =power_supply_for_each_psy (supply_node, __power_supply_find_supply_from_node);return error ? (error ==1 ?0 : error) : -EPROBE_DEFER ; }
@@ -332,10 +329,9 @@ struct psy_am_i_supplied_data {unsigned int count; }; -static int __power_supply_am_i_supplied (struct device *dev,void *_data) +static int __power_supply_am_i_supplied (struct power_supply *epsy,void *_data) {union power_supply_propval ret = {0 ,}; -struct power_supply *epsy =dev_get_drvdata (dev);struct psy_am_i_supplied_data *data = _data;if (__power_supply_is_supplied_by (epsy, data->psy)) {
@@ -353,7 +349,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)struct psy_am_i_supplied_data data = { psy,0 };int error; - error =power_supply_for_each_device (&data, __power_supply_am_i_supplied); + error =power_supply_for_each_psy (&data, __power_supply_am_i_supplied);dev_dbg (&psy->dev,"%s count %u err %d\n" , __func__, data.count, error);
@@ -364,10 +360,9 @@ int power_supply_am_i_supplied(struct power_supply *psy) }EXPORT_SYMBOL_GPL (power_supply_am_i_supplied); -static int __power_supply_is_system_supplied (struct device *dev,void *data) +static int __power_supply_is_system_supplied (struct power_supply *psy,void *data) {union power_supply_propval ret = {0 ,}; -struct power_supply *psy =dev_get_drvdata (dev);unsigned int *count = data;if (!psy->desc->get_property (psy,POWER_SUPPLY_PROP_SCOPE , &ret))
@@ -388,7 +383,7 @@ int power_supply_is_system_supplied(void)int error;unsigned int count =0 ; - error =power_supply_for_each_device (&count, __power_supply_is_system_supplied); + error =power_supply_for_each_psy (&count, __power_supply_is_system_supplied);/* * If no system scope power class device was found at all, most probably we
@@ -407,9 +402,8 @@ struct psy_get_supplier_prop_data {union power_supply_propval *val; }; -static int __power_supply_get_supplier_property (struct device *dev,void *_data) +static int __power_supply_get_supplier_property (struct power_supply *epsy,void *_data) { -struct power_supply *epsy =dev_get_drvdata (dev);struct psy_get_supplier_prop_data *data = _data;if (__power_supply_is_supplied_by (epsy, data->psy))
@@ -434,7 +428,7 @@ int power_supply_get_property_from_supplier(struct power_supply *psy,* This function is not intended for use with a supply with multiple * suppliers, we simply pick the first supply to report the psp. */ - ret =power_supply_for_each_device (&data, __power_supply_get_supplier_property); + ret =power_supply_for_each_psy (&data, __power_supply_get_supplier_property);if (ret <0 )return ret;if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1838/3318 power: supply: core: get rid of of_node
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 134254038739a6c6ecb7548a2f895d89a0dc9d2a ]
This removes .of_node from 'struct power_supply', since there is already a copy in .dev.of_node and there is no need to have two copies.
Stable-dep-of: 6bd80f22c764 ("power: supply: core: Honor supplied-from with CONFIG_OF=y")
--- drivers/power/supply/power_supply_core.c | 16 ++++++++-------- include/linux/power_supply.h | 1 - 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/power/supply/power_supply_core.c +8 -8
@@ -194,11 +194,11 @@ static int __power_supply_populate_supplied_from(struct power_supply *epsy,int i =0 ; do { - np = of_parse_phandle(psy->of_node, "power-supplies", i++); + np = of_parse_phandle(psy->dev.of_node, "power-supplies", i++); if (!np) break; - if (np == epsy->of_node) { + if (np == epsy->dev.of_node) { dev_dbg(&psy->dev, "%s: Found supply : %s\n", psy->desc->name, epsy->desc->name); psy->supplied_from[i-1] = (char *)epsy->desc->name;
@@ -229,7 +229,7 @@ static int __power_supply_find_supply_from_node(struct power_supply *epsy,struct device_node *np = data;/* returning non-zero breaks out of power_supply_for_each_psy loop */ -if (epsy->of_node == np) +if (epsy->dev.of_node == np)return 1 ;return 0 ;
@@ -264,13 +264,13 @@ static int power_supply_check_supplies(struct power_supply *psy)return 0 ;/* No device node found, nothing to do */ -if (!psy->of_node) +if (!psy->dev.of_node)return 0 ; do { int ret; - np = of_parse_phandle(psy->of_node, "power-supplies", cnt++); + np = of_parse_phandle(psy->dev.of_node, "power-supplies", cnt++); if (!np) break;
@@ -595,8 +595,8 @@ int power_supply_get_battery_info(struct power_supply *psy,const __be32 *list;u32 min_max[2 ]; -if (psy->of_node) { - battery_np =of_parse_phandle (psy->of_node,"monitored-battery" ,0 ); +if (psy->dev.of_node) { + battery_np =of_parse_phandle (psy->dev.of_node,"monitored-battery" ,0 );if (!battery_np)return -ENODEV ;
@@ -1390,7 +1390,7 @@ __power_supply_register(struct device *parent,if (cfg) { dev->groups = cfg->attr_grp; psy->drv_data = cfg->drv_data; - psy->of_node = + dev->of_node = cfg->fwnode ?to_of_node (cfg->fwnode) : cfg->of_node; psy->supplied_to = cfg->supplied_to; psy->num_supplicants = cfg->num_supplicants;
include/linux/power_supply.h +0 -1
@@ -287,7 +287,6 @@ struct power_supply {char **supplied_from;size_t num_supplies; -struct device_node *of_node;/* Driver private data */ void *drv_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1839/3318 power: supply: core: Honor supplied-from with CONFIG_OF=y
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maurizio Casciano <[email protected]>
[ Upstream commit 6bd80f22c764fe8c56c62c118387f86a3ca98cff ]
The supplied-from device property is the name-based counterpart to firmware-node power-supplies references. It was added for non-DT platforms, but its parser is compiled only when CONFIG_OF is disabled. CONFIG_OF is a global kernel option, so x86 systems commonly enable it even when individual power supplies are described by software nodes.
Consequently, these consumers never populate supplied_from and supplier notifications do not reach their external_power_changed() callbacks. On a Lenovo Yoga Book YB1-X91L, ftrace showed the Whiskey Cove supplier notification running without invoking the BQ25892 callback, leaving the input current limit at its boot-time value.
Use a single power_supply_check_supplies() implementation for all configurations. Preserve firmware-node power-supplies references as the preferred firmware description and use the name-based supplied-from property only when no references are specified. Continue to honor an explicitly provided supplied_from list first and propagate errors from specified firmware references.
With the fix, ftrace shows the BQ25892 callback on hotplug. A boot-offline test changes its input current limit from 500 mA to 2 A.
--- drivers/power/supply/power_supply_core.c | 90 ++++++++++++------------ 1 file changed, 45 insertions(+), 45 deletions(-)
drivers/power/supply/power_supply_core.c +45 -45
@@ -185,7 +185,35 @@ static void power_supply_deferred_register_work(struct work_struct *work)mutex_unlock (&psy->dev.parent->mutex); } -#ifdef CONFIG_OF +static int power_supply_check_supplies_by_name (struct power_supply *psy) +{ +struct device *parent = psy->dev.parent; +int nval, ret; + +if (!parent) +return 0 ; + + nval =device_property_string_array_count (parent,"supplied-from" ); +if (nval <=0 ) +return 0 ; + + psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, +sizeof (*psy->supplied_from), +GFP_KERNEL ); +if (!psy->supplied_from) +return -ENOMEM ; + + ret =device_property_read_string_array (parent,"supplied-from" , + (const char **)psy->supplied_from, + nval); +if (ret <0 ) +return ret; + + psy->num_supplies = nval; + +return 0 ; +} +static int __power_supply_populate_supplied_from (struct power_supply *epsy,void *data) {
@@ -256,73 +284,45 @@ static int power_supply_find_supply_from_node(struct device_node *supply_node)static int power_supply_check_supplies (struct power_supply *psy) { -struct device_node *np; -int cnt =0 ; +struct of_phandle_args args; +int cnt, ret;/* If there is already a list honor it */ if (psy->supplied_from && psy->num_supplies >0 )return 0 ; -/* No device node found, nothing to do */ -if (!psy->dev.of_node) -return 0 ; - -do { -int ret; +for (cnt =0 ; psy->dev.of_node; cnt++) { + ret =of_parse_phandle_with_fixed_args (psy->dev.of_node, +"power-supplies" ,0 , cnt, &args); +if (ret) { +if (ret != -ENOENT ) +return ret; - np =of_parse_phandle (psy->dev.of_node,"power-supplies" , cnt++); -if (!np)break ; + } - ret =power_supply_find_supply_from_node (np); -of_node_put (np); + ret =power_supply_find_supply_from_node (args.np); +of_node_put (args.np);if (ret) {dev_dbg (&psy->dev,"Failed to find supply!\n" );return ret; } - }while (np); + } -/* Missing valid "power-supplies" entries */ -if (cnt ==1 ) -return 0 ; +/* Fall back to the name-based property if no references were specified. */ +if (!cnt) +return power_supply_check_supplies_by_name (psy);/* All supplies found, allocate char * array for filling */ psy->supplied_from =devm_kcalloc (&psy->dev, - cnt -1 ,sizeof (*psy->supplied_from), + cnt,sizeof (*psy->supplied_from),GFP_KERNEL );if (!psy->supplied_from)return -ENOMEM ;return power_supply_populate_supplied_from (psy); } -#else -static int power_supply_check_supplies (struct power_supply *psy) -{ -int nval, ret; - -if (!psy->dev.parent) -return 0 ; - - nval =device_property_string_array_count (psy->dev.parent,"supplied-from" ); -if (nval <=0 ) -return 0 ; - - psy->supplied_from =devm_kmalloc_array (&psy->dev, nval, -sizeof (char *),GFP_KERNEL ); -if (!psy->supplied_from) -return -ENOMEM ; - - ret =device_property_read_string_array (psy->dev.parent, -"supplied-from" , (const char **)psy->supplied_from, nval); -if (ret <0 ) -return ret; - - psy->num_supplies = nval; - -return 0 ; -} -#endif struct psy_am_i_supplied_data {struct power_supply *psy;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1840/3318 fbdev: nvidia: Release write-combining handle on probe failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 8710af6a35201a6d01b5af8f7e4bad29cc40467f ]
Failures in nvidia_set_fbinfo() or register_framebuffer() leave the handle from arch_phys_wc_add() allocated. Release it in the shared error path, as nvidiafb_remove() already does on normal removal.
The missing cleanup was already present in the initial Git import, when the driver used mtrr_add() directly.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/fbdev/nvidia/nvidia.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/nvidia/nvidia.c +1 -0
@@ -1417,6 +1417,7 @@ static int nvidiafb_probe(struct pci_dev *pd, const struct pci_device_id *ent)return 0 ; err_out_iounmap_fb: +arch_phys_wc_del (par->wc_cookie);iounmap (info->screen_base);fb_destroy_modelist (&info->modelist); err_out_free_base1:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1841/3318 platform/x86/amd/pmf: Add AMDI0112 ACPI ID
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 325bcc126cf7a512a0e2da0efddad665f69badac ]
The AMDI0112 ID is used to bind the PMF driver to some platforms. It doesn't have any Linux side code changes relative to the most similar AMDI0105.
--- drivers/platform/x86/amd/pmf/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/platform/x86/amd/pmf/core.c +1 -0
@@ -342,6 +342,7 @@ static const struct acpi_device_id amd_pmf_acpi_ids[] = { {"AMDI0100", 0x100}, {"AMDI0102", 0}, {"AMDI0103", 0}, + {"AMDI0112", 0}, { } };MODULE_DEVICE_TABLE (acpi, amd_pmf_acpi_ids);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1842/3318 power: supply: qcom_battmgr: Notify charger supplies of online changes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brandon Williams <[email protected]>
[ Upstream commit 87fd20da8ca8bacdaa9bff5860167f208077dc51 ]
On SC8280XP and X1E80100 the AC, USB and wireless supplies take their online state from the charging source in the battery status response. The firmware sends no notification for those supplies when the charging source changes, and the driver only announces the battery, so userspace never learns that the charger was plugged in or out. UPower keeps the state it read at startup: a laptop booted on the charger never goes on battery.
Call power_supply_changed() for a supply whose online state changes when a status response is parsed. A supply that is not registered yet, when the battery is read during probe, reports its state when it registers.
Tested on a Microsoft Surface Pro 11 (X1E80100): after restarting UPower on the charger, unplugging now sets OnBattery, and plugging in clears it.
--- drivers/power/supply/qcom_battmgr.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/power/supply/qcom_battmgr.c +23 -3
@@ -995,6 +995,23 @@ static unsigned int qcom_battmgr_sc8280xp_convert_temp(unsigned int temperature)return DIV_ROUND_CLOSEST (temperature,10 ); } +/* +* The charger supplies' online state comes from the battery status response, +* and the firmware sends no notification of its own when it changes, so +* announce the change here. A supply that is not registered yet announces its +* state when it is. +*/ +static void qcom_battmgr_sc8280xp_set_online (struct power_supply *psy, +bool *online,bool value) +{ +if (*online == value) +return ; + + *online = value; +if (psy) +power_supply_changed (psy); +} +static void qcom_battmgr_sc8280xp_callback (struct qcom_battmgr *battmgr,const struct qcom_battmgr_message *resp,size_t len)
@@ -1062,9 +1079,12 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr, battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); source =le32_to_cpu (resp->status.charging_source); - battmgr->ac.online = source ==BATTMGR_CHARGING_SOURCE_AC ; - battmgr->usb.online = source ==BATTMGR_CHARGING_SOURCE_USB ; - battmgr->wireless.online = source ==BATTMGR_CHARGING_SOURCE_WIRELESS ; +qcom_battmgr_sc8280xp_set_online (battmgr->ac_psy, &battmgr->ac.online, + source ==BATTMGR_CHARGING_SOURCE_AC ); +qcom_battmgr_sc8280xp_set_online (battmgr->usb_psy, &battmgr->usb.online, + source ==BATTMGR_CHARGING_SOURCE_USB ); +qcom_battmgr_sc8280xp_set_online (battmgr->wls_psy, &battmgr->wireless.online, + source ==BATTMGR_CHARGING_SOURCE_WIRELESS );break ;case BATTMGR_BAT_DISCHARGE_TIME : battmgr->status.discharge_time =le32_to_cpu (resp->time);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1843/3318 drm/amdkfd: stop restore retries on device unplug
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Olivier Kaloudoff <[email protected]>
[ Upstream commit 3254ed0b15f2fe656c9cb36ccb59b92422440bf8 ]
amdgpu_amdkfd_restore_userptr_worker() and svm_range_restore_work() reschedule themselves when validation fails with evicted objects pending. After a surprise removal the restore paths fail with -ENODEV permanently, so rescheduling just spins the worker uselessly until cancel_delayed_work_sync() in fini finally stops it - which can take a while, since process teardown itself is delayed by the dead device.
Treat -ENODEV as terminal in both workers.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 18 +++++++++++++----- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +13 -5
@@ -2700,6 +2700,7 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)struct task_struct *usertask;struct mm_struct *mm;uint32_t evicted_bos; +int ret;mutex_lock (&process_info->notifier_lock); evicted_bos = process_info->evicted_bos;
@@ -2719,14 +2720,16 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)mutex_lock (&process_info->lock); -if (update_invalid_user_pages (process_info, mm)) + ret =update_invalid_user_pages (process_info, mm); +if (ret) goto unlock_out;/* userptr_inval_list can be empty if all evicted userptr BOs * have been freed. In that case there is nothing to validate * and we can just restart the queues. */ if (!list_empty (&process_info->userptr_inval_list)) { -if (validate_invalid_user_pages (process_info)) + ret =validate_invalid_user_pages (process_info); +if (ret) goto unlock_out; }/* Final check for concurrent evicton and atomic update. If
@@ -2735,11 +2738,14 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work)* reference counting inside KFD will handle this case. */ mutex_lock (&process_info->notifier_lock); -if (process_info->evicted_bos != evicted_bos) +if (process_info->evicted_bos != evicted_bos) { + ret = -EAGAIN ; goto unlock_notifier_out; + }if (confirm_valid_user_pages_locked (process_info)) {WARN (1 ,"User pages unexpectedly invalid" ); + ret = -EINVAL ; goto unlock_notifier_out; }
@@ -2757,8 +2763,10 @@ static void amdgpu_amdkfd_restore_userptr_worker(struct work_struct *work) unlock_out:mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_bos) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_bos && ret != -ENODEV ) {schedule_delayed_work (&process_info->restore_userptr_work,msecs_to_jiffies (AMDGPU_USERPTR_RESTORE_DELAY_MS ));
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -3
@@ -1821,7 +1821,7 @@ static void svm_range_restore_work(struct work_struct *work)struct mm_struct *mm;int evicted_ranges;int invalid; -int r; +int r =0 ; svms = container_of(dwork, struct svm_range_list, restore_work); evicted_ranges =atomic_read (&svms->evicted_ranges);
@@ -1895,8 +1895,10 @@ static void svm_range_restore_work(struct work_struct *work)mmap_write_unlock (mm);mutex_unlock (&process_info->lock); -/* If validation failed, reschedule another attempt */ -if (evicted_ranges) { +/* If validation failed, reschedule another attempt, unless the +* device is gone for good +*/ +if (evicted_ranges && r != -ENODEV ) {pr_debug ("reschedule to restore svm range\n" );schedule_delayed_work (&svms->restore_work,msecs_to_jiffies (AMDGPU_SVM_RANGE_RESTORE_DELAY_MS ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1844/3318 lib/tests: extend cmdline KUnit with next_arg() tests
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuvam Pandey <[email protected]>
[ Upstream commit dcc8a57815534e3844f342b28ecfb6e626a816a0 ]
The cmdline KUnit suite covers get_option() and get_options(), but it does not exercise next_arg().
Extend the suite with one test for a quoted value containing spaces and one regression test for a bare quote token after a normal parameter.
The regression test covers the bare quote token path fixed by commit 9847f21225c4 ("lib/cmdline: avoid page fault in next_arg").
Stable-dep-of: 5d72266218b1 ("lib/cmdline: fix get_options() count and overflow with large ranges")
--- lib/cmdline_kunit.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
lib/cmdline_kunit.c +62 -0
@@ -139,11 +139,73 @@ static void cmdline_test_range(struct kunit *test) }while (++i <ARRAY_SIZE (cmdline_test_range_strings)); } +static void cmdline_test_next_arg_quoted_value (struct kunit *test) +{ +char in[] ="foo=\"bar baz\" qux=1" ; +char *next, *param, *val; + + next =next_arg (in, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"foo" ); +KUNIT_ASSERT_NOT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, val,"bar baz" ); +KUNIT_EXPECT_STREQ (test, next,"qux=1" ); + + next =next_arg (next, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"qux" ); +KUNIT_ASSERT_NOT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, val,"1" ); +KUNIT_EXPECT_STREQ (test, next,"" ); +} + +static void cmdline_test_next_arg_bare_quote_regression (struct kunit *test) +{ +char in[] ="foo=bar \"" ; +char *next, *param, *val; + + next =next_arg (in, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"foo" ); +KUNIT_ASSERT_NOT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, val,"bar" ); +KUNIT_EXPECT_STREQ (test, next,"\"" ); + +/* This hits the i == 0 quoted-token case fixed by 9847f21225c4. */ + next =next_arg (next, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"" ); +KUNIT_EXPECT_PTR_EQ (test, val,NULL ); +KUNIT_EXPECT_STREQ (test, next,"" ); +} + +static void cmdline_test_next_arg_mixed_tokens (struct kunit *test) +{ +char in[] ="bbb= jjj kkk=\"a=b\"" ; +char *next, *param, *val; + + next =next_arg (in, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"bbb" ); +KUNIT_ASSERT_NOT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, val,"" ); +KUNIT_EXPECT_STREQ (test, next,"jjj kkk=\"a=b\"" ); + + next =next_arg (next, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"jjj" ); +KUNIT_EXPECT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, next,"kkk=\"a=b\"" ); + + next =next_arg (next, ¶m, &val); +KUNIT_EXPECT_STREQ (test, param,"kkk" ); +KUNIT_ASSERT_NOT_NULL (test, val); +KUNIT_EXPECT_STREQ (test, val,"a=b" ); +KUNIT_EXPECT_STREQ (test, next,"" ); +} +static struct kunit_case cmdline_test_cases[] = {KUNIT_CASE (cmdline_test_noint),KUNIT_CASE (cmdline_test_lead_int),KUNIT_CASE (cmdline_test_tail_int),KUNIT_CASE (cmdline_test_range), +KUNIT_CASE (cmdline_test_next_arg_quoted_value), +KUNIT_CASE (cmdline_test_next_arg_bare_quote_regression), +KUNIT_CASE (cmdline_test_next_arg_mixed_tokens), {} };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1845/3318 lib/cmdline: fix get_options() count and overflow with large ranges
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armaan Sandhu <[email protected]>
[ Upstream commit 5d72266218b1c4dd2917f1df2b86f3b0e0a605c9 ]
get_range() stops writing once the array is full, but get_options() still advances its index by the whole range. So "1-100" parsed into four ints reports 99 numbers, and a range like "0-2147483647" wraps the index negative and writes outside the array.
Stop once a range fills the array, bail out in validation mode before the count overflows, and saturate the range length in get_range(). Add KUnit cases; without the fix "0-2147483647" panics the test kernel.
Only root can supply this input, so this is a robustness fix.
--- lib/cmdline.c | 13 ++++++++++++- lib/cmdline_kunit.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
lib/cmdline.c +12 -1
@@ -11,6 +11,7 @@#include <linux/export.h> #include <linux/kernel.h> +#include <linux/overflow.h> #include <linux/string.h> #include <linux/ctype.h>
@@ -26,7 +27,9 @@ static int get_range(char **str, int *pint, int n) (*str)++; upper_range =simple_strtol ((*str),NULL ,0 ); - inc_counter = upper_range - *pint; +/* Keep the sign of the result when the difference doesn't fit */ +if (check_sub_overflow (upper_range, *pint, &inc_counter)) + inc_counter = upper_range < *pint ?-1 :INT_MAX ;for (x = *pint; n && x < upper_range; x++, n--) *pint++ = x;return inc_counter;
@@ -122,6 +125,14 @@ char *get_options(const char *str, int nints, int *ints) range_nums =get_range ((char **)&str, pint, n);if (range_nums <0 )break ; +/* The range didn't fit, so the array is full */ +if (!validate && range_nums > n) { + i = nints; +break ; + } +/* Leave room for the upper number of the range */ +if (range_nums >=INT_MAX - i) +break ;/* * Decrement the result by one to leave out the * last number in the range. The next iteration
lib/cmdline_kunit.c +39 -0
@@ -139,6 +139,44 @@ static void cmdline_test_range(struct kunit *test) }while (++i <ARRAY_SIZE (cmdline_test_range_strings)); } +static const struct { +const char *in; +int parsed[4 ]; +int validated; +} cmdline_test_range_overflow_cases[] = { + {"1-100" , {3 ,1 ,2 ,3 , },100 , }, + {"1,5-100,7" , {3 ,1 ,5 ,6 , },98 , }, + {"1-2147483646" , {3 ,1 ,2 ,3 , },2147483646 , }, + {"0-2147483647" , {3 ,0 ,1 ,2 , },0 , }, + {"-5-2147483647" , {3 ,-5 ,-4 ,-3 , },0 , }, + {"2147483647--5" , {0 ,2147483647 , },0 , }, + {"1,0-2147483647" , {3 ,1 ,0 ,1 , },1 , }, +}; + +static void cmdline_test_range_overflow (struct kunit *test) +{ +unsigned int i, j; + +for (i =0 ; i <ARRAY_SIZE (cmdline_test_range_overflow_cases); i++) { +const char *in = cmdline_test_range_overflow_cases[i].in; +const int *e = cmdline_test_range_overflow_cases[i].parsed; +/* Two guard elements past the array handed to get_options() */ +int r[ARRAY_SIZE (cmdline_test_range_overflow_cases[0 ].parsed) +2 ]; +int n; + +memset (r,0 ,sizeof (r)); +get_options (in,ARRAY_SIZE (r) -2 , r); +for (j =0 ; j <ARRAY_SIZE (r) -2 ; j++) +KUNIT_EXPECT_EQ_MSG (test, r[j], e[j],"Pattern: %s at %u" , in, j); +for (; j <ARRAY_SIZE (r); j++) +KUNIT_EXPECT_EQ_MSG (test, r[j],0 ,"Pattern: %s out of bound at %u" , in, j); + +get_options (in,0 , &n); +KUNIT_EXPECT_EQ_MSG (test, n, cmdline_test_range_overflow_cases[i].validated, +"Pattern: %s (validated)" , in); + } +} +static void cmdline_test_next_arg_quoted_value (struct kunit *test) {char in[] ="foo=\"bar baz\" qux=1" ;
@@ -203,6 +241,7 @@ static struct kunit_case cmdline_test_cases[] = {KUNIT_CASE (cmdline_test_lead_int),KUNIT_CASE (cmdline_test_tail_int),KUNIT_CASE (cmdline_test_range), +KUNIT_CASE (cmdline_test_range_overflow),KUNIT_CASE (cmdline_test_next_arg_quoted_value),KUNIT_CASE (cmdline_test_next_arg_bare_quote_regression), KUNIT_CASE(cmdline_test_next_arg_mixed_tokens),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1846/3318 ata: libata: Do not leave ata_host_stop() registered when activation fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit d2f977008cbbae195df678ee1e70e5802f9bd0b8 ]
ata_host_start() registers ata_host_stop() as a devres action as soon as it has succeeded, which hands the release of the host resources over to
devres: ->port_stop() and ->host_stop() are then called by the driver core when probe() fails.
ata_host_activate() and ahci_host_activate_multi_irqs() can both fail after ata_host_start() has succeeded, e.g. if devm_request_irq() or ata_host_register() fails, and they return the error with the devres action still registered. A driver which releases the host resources in its probe() error path therefore releases them twice: once itself and once through ->host_stop().
All ahci-platform drivers are in that situation, e.g. ahci_probe() calls ahci_platform_disable_resources() while ahci_host_stop() does the same through devres. This gives refcount underflow warnings from the clk, regulator and phy cores and, for shared resources, can disable resources which are still in use by other devices.
Add ata_host_undo_start(), which stops the ports and drops the devres action without calling ->host_stop(), and call it from both activation helpers when they fail. Releasing the host resources on failure is then always left to the caller, which is what all callers having a probe() error path already assume.
This changes the semantics for the drivers which implement ->host_stop() while also completely lacking error handling for the activate host call. Add activate host error handling for sata_qstor and sata_fsl. For sata_fsl this also means that hcr_base and host_priv are now released when activating the host fails, which ->host_stop() did not do when ata_host_start() itself failed.
Note that ata_pci_sff_activate_host() is deliberately left as is: none of its callers releases the host resources in its probe() error path, they all rely on ->host_stop() being called by devres, including ata_pci_init_one(), which releases the devres group of the host itself.
--- drivers/ata/libahci.c | 2 + drivers/ata/libahci_platform.c | 4 ++ drivers/ata/libata-core.c | 75 +++++++++++++++++++++++++++++++--- drivers/ata/libata-sff.c | 5 +++ drivers/ata/sata_fsl.c | 6 ++- drivers/ata/sata_qstor.c | 8 +++- include/linux/libata.h | 1 + 7 files changed, 91 insertions(+), 10 deletions(-)
drivers/ata/libahci.c +2 -0
@@ -2761,6 +2761,8 @@ static int ahci_host_activate_multi_irqs(struct ata_host *host, host->ports[i]); } +ata_host_undo_start (host); +return rc; }
drivers/ata/libahci_platform.c +4 -0
@@ -692,6 +692,10 @@ EXPORT_SYMBOL_GPL(ahci_platform_get_resources);* ahci-platform host, note any necessary resources (ie clks, phys, etc.) * must be initialized / enabled before calling this. * +* On failure, ->host_stop() is not called, so the caller has to release the +* resources it enabled (clocks, regulators, resets, PHYs) in its probe() +* error path. +* * RETURNS: * 0 on success otherwise a negative error code */
drivers/ata/libata-core.c +69 -6
114 lines not on this page · raw message
drivers/ata/libata-sff.c +5 -0
@@ -2265,6 +2265,11 @@ EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host);* hosts. This separate helper is necessary because SFF hosts * use two separate interrupts in legacy mode. * +* Note that, unlike ata_host_activate(), the devres action registered +* by ata_host_start() is kept on failure, i.e. ->host_stop() is called +* by the driver core when probe() fails. All callers of this function +* rely on that, none of them releases the host resources itself. +* * LOCKING: * Inherited from calling layer (may sleep). *
drivers/ata/sata_fsl.c +4 -2
@@ -1489,8 +1489,10 @@ static int sata_fsl_probe(struct platform_device *ofdev)* device discovery process, invoking our port_start() handler & * error_handler() to execute a dummy Softreset EH session */ -ata_host_activate (host, irq, sata_fsl_interrupt,SATA_FSL_IRQ_FLAG , - &sata_fsl_sht); + retval =ata_host_activate (host, irq, sata_fsl_interrupt, +SATA_FSL_IRQ_FLAG , &sata_fsl_sht); +if (retval) + goto error_exit_with_cleanup; host_priv->intr_coalescing.show = fsl_sata_intr_coalescing_show; host_priv->intr_coalescing.store = fsl_sata_intr_coalescing_store;
drivers/ata/sata_qstor.c +6 -2
@@ -584,8 +584,12 @@ static int qs_ata_init_one(struct pci_dev *pdev,qs_host_init (host, board_idx);pci_set_master (pdev); -return ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , - &qs_ata_sht); + rc =ata_host_activate (host, pdev->irq, qs_intr,IRQF_SHARED , + &qs_ata_sht); +if (rc) +qs_host_stop (host); + +return rc; }module_pci_driver (qs_ata_pci_driver);
include/linux/libata.h +1 -0
@@ -1075,6 +1075,7 @@ extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,extern void ata_host_get (struct ata_host *host);extern void ata_host_put (struct ata_host *host);extern int ata_host_start (struct ata_host *host); +void ata_host_undo_start (struct ata_host *host);extern int ata_host_register (struct ata_host *host,const struct scsi_host_template *sht); extern int ata_host_activate(struct ata_host *host, int irq,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1847/3318 media: sti: delta: use unaligned accessors for MJPEG SOF fields
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit fdc5bf02aeaef04e7d13895db9b6eaf8083953f9 ]
delta_mjpeg_read_header() scans a compressed MJPEG access unit byte by byte and passes the bytes after an SOF marker to delta_mjpeg_read_sof(). The SOF parser then reads 16-bit big-endian fields directly from that byte stream.
The SOF payload is not an aligned object. The marker scan can find the payload at any byte position, and the SOF layout also puts frame_height and frame_width after a one-byte sample_precision field. Those fields therefore sit at odd offsets within the payload even when the payload base happens to be 2-byte aligned.
Avoid casting the byte stream to __be16 pointers and use get_unaligned_be16() for the SOF length, height, and width fields.
This issue was detected by our static analysis tool and confirmed by manual audit. A focused UBSAN alignment validation of the same typed load shape reported a misaligned __be16 access in delta_mjpeg_read_sof().
--- drivers/media/platform/st/sti/delta/delta-mjpeg-hdr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/platform/st/sti/delta/delta-mjpeg-hdr.c +4 -3
@@ -4,6 +4,7 @@* Author: Hugues Fruchet <[email protected]> for STMicroelectronics. */ +#include <asm/unaligned.h> #include "delta.h" #include "delta-mjpeg.h"
@@ -48,13 +49,13 @@ static int delta_mjpeg_read_sof(struct delta_ctx *pctx, goto err_no_more;memset (header,0 ,sizeof (*header)); - header->length =be16_to_cpu (*(__be16 *)(data + offset)); + header->length =get_unaligned_be16 (data + offset); offset +=sizeof (u16); header->sample_precision = *(u8 *)(data + offset); offset +=sizeof (u8); - header->frame_height =be16_to_cpu (*(__be16 *)(data + offset)); + header->frame_height =get_unaligned_be16 (data + offset); offset +=sizeof (u16); - header->frame_width =be16_to_cpu (*(__be16 *)(data + offset)); + header->frame_width =get_unaligned_be16 (data + offset); offset +=sizeof (u16); header->nb_of_components = *(u8 *)(data + offset); offset +=sizeof (u8);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1848/3318 ASoC: amd: yc: Add DMI quirk for HP OmniBook 3 Laptop 16-by0xxx
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gianluca Balboni <[email protected]>
[ Upstream commit 1e73257dff33ff851af60d5bb00d73893a8b6dc8 ]
The HP OmniBook 3 Laptop 16-by0xxx (board ID 8EE3) has an internal DMIC connected to the AMD ACP6x audio coprocessor. The BIOS does not set the AcpDmicConnected _DSD property or the _WOV method, and the board is missing from yc_acp_quirk_table[], so acp6x_probe() returns -ENODEV and no DMIC capture device is registered.
Add a DMI quirk entry for this model to enable ACP DMIC support.
--- sound/soc/amd/yc/acp6x-mach.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/soc/amd/yc/acp6x-mach.c +7 -0
@@ -675,6 +675,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = { DMI_MATCH(DMI_BOARD_NAME, "8BD6"), } }, + { + .driver_data = &acp6x_card, + .matches = { +DMI_MATCH (DMI_BOARD_VENDOR ,"HP" ), + DMI_MATCH(DMI_BOARD_NAME, "8EE3"), + } + }, { .driver_data = &acp6x_card, .matches = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1849/3318 f2fs: Fix not used variable index
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zeng Heng <[email protected]>
[ Upstream commit 0c3a38a4b442893f8baca72e44a2a27d52d6cc75 ]
Fix the following compilation warning:fs/f2fs/data.c:2391:10: warning: variable ‘index’ set but not used [-Wunused-but-set-variable]
2391 | pgoff_t index;
Only define and set the variable index when the CONFIG_F2FS_FS_COMPRESSION is enabled.
--- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/data.c +2 -2
@@ -2392,10 +2392,10 @@ static int f2fs_mpage_readpages(struct inode *inode, .nr_cpages = 0, };pgoff_t nc_cluster_idx =NULL_CLUSTER ; +pgoff_t index;#endif unsigned nr_pages = rac ?readahead_count (rac) :1 ;unsigned max_nr_pages = nr_pages; -pgoff_t index;int ret =0 ; map.m_pblk =0 ;
@@ -2413,9 +2413,9 @@ static int f2fs_mpage_readpages(struct inode *inode,prefetchw (&folio->flags); } +#ifdef CONFIG_F2FS_FS_COMPRESSION index =folio_index (folio); -#ifdef CONFIG_F2FS_FS_COMPRESSION if (!f2fs_compressed_file (inode)) goto read_single_page;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1850/3318 assoc_array: dont lose objects when a shortcut is split on a word boundary
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 2a62c32760a8fbf464a7388853d19bc62c5cc423 ]
When assoc_array_insert_mid_shortcut() splits a shortcut at level diff, the new shortcut in front of the split, new_s0, gets the first round_up(diff, ASSOC_ARRAY_KEY_CHUNK_SIZE) bits of the old shortcut's index key, and the bits from diff onwards are then cleared from its last word:
blank = ULONG_MAX << (diff & ASSOC_ARRAY_KEY_CHUNK_MASK); new_s0->index_key[keylen - 1] &= ~blank;
When diff is a multiple of ASSOC_ARRAY_KEY_CHUNK_SIZE, the shift is 0, blank is all ones, and the whole last word is cleared, although all of it lies below diff. A walk then compares the key it is looking for against that zeroed word, takes the shortcut to point elsewhere, and every object below it can no longer be found.
assoc_array_insert_into_terminal_node() trims a new shortcut's key the same way, and only when the level is not a multiple of the chunk size. Do the same here.
Found by a userspace build of the array with a test that inserts, in order, string keys whose first word is their length and the rest their bytes. The 102nd key split a shortcut at bit 256, and 76 of the keys already in the array could no longer be found; AddressSanitizer also reported assoc_array_walk() reading a word past the end of a shortcut's index key. With this change the test passes, and AddressSanitizer and UndefinedBehaviorSanitizer report nothing.
--- lib/assoc_array.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/assoc_array.c +5 -3
@@ -866,9 +866,11 @@ static bool assoc_array_insert_mid_shortcut(struct assoc_array_edit *edit,memcpy (new_s0->index_key, shortcut->index_key,flex_array_size (new_s0, index_key, keylen)); - blank =ULONG_MAX << (diff &ASSOC_ARRAY_KEY_CHUNK_MASK ); -pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , diff, blank); - new_s0->index_key[keylen -1 ] &= ~blank; +if (diff &ASSOC_ARRAY_KEY_CHUNK_MASK ) { + blank =ULONG_MAX << (diff &ASSOC_ARRAY_KEY_CHUNK_MASK ); +pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , diff, blank); + new_s0->index_key[keylen -1 ] &= ~blank; + } }else {pr_devel ("no pre-shortcut\n" ); edit->set[0 ].to =assoc_array_node_to_ptr (new_n0);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1851/3318 assoc_array: dont lose objects when a root shortcut is split at level 4
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 20b436c1ae8d37032f888c725915729830dc52f2 ]
assoc_array_insert_mid_shortcut() takes level, the level of the node holding the shortcut as assoc_array_walk() reports it, and adds ASSOC_ARRAY_LEVEL_STEP to get the level of a node in that shortcut's place. If the new key first differs from the shortcut no further in than that, no shortcut is made in front of the split, and new_n0 takes the old shortcut's place directly.
A shortcut at the root is held by no node. assoc_array_walk() reports level 0 for it, and whatever takes its place is the root, which is read at level 0. So when the new key first differs from a root shortcut in bits 4-7, diff is 4, no shortcut is made in front, and new_n0, whose slots are indexed by bits 4-7, becomes the root and is indexed by bits 0-3. Objects already in the array can no longer be found, and the new one lands in a slot its key does not select.
Eighteen keys are enough: seventeen that agree on bits 0-7 make the root a shortcut, and one that agrees with them on bits 0-3 only splits it. Three of the eighteen objects can then not be found, and inserting one of those keys again adds a second object instead of replacing it.
Only add the step for a shortcut that hangs from a node. A root shortcut split at level 4 then gets a shortcut in front of the split that ends at level 4, as assoc_array_insert_into_terminal_node() already makes when the leaves of a full root node first differ there.
Found by a userspace test that builds a shortcut ending at every level and splits it at every level inside it, from the root and from a node:
every split of a root shortcut at level 4 failed, and nothing else did.
--- lib/assoc_array.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/assoc_array.c +2 -1
@@ -843,7 +843,8 @@ static bool assoc_array_insert_mid_shortcut(struct assoc_array_edit *edit,* zero length - otherwise we just connect the new node directly to the * parent. */ - level +=ASSOC_ARRAY_LEVEL_STEP ; +if (shortcut->back_pointer) + level +=ASSOC_ARRAY_LEVEL_STEP ;if (diff > level) {pr_devel ("pre-shortcut %d...%d\n" , level, diff); keylen =round_up (diff,ASSOC_ARRAY_KEY_CHUNK_SIZE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1852/3318 assoc_array: move in-place insertion into a function of its own
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit a624a7ce7d85b514d949b6c7a049f43ac96f3257 ]
assoc_array_insert_into_terminal_node() is over 300 lines and does four jobs, joined by gotos: putting the new leaf in place of a matching one or in a free slot, working out the segment of each leaf, splitting the node, and replacing the node with a shortcut. The last two share the function's tail, which installs the replacement where the node was.
Move the jobs into functions of their own, one per commit, starting with the two cases that need no new node: assoc_array_insert_in_node().
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 68 ++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 25 deletions(-)
lib/assoc_array.c +43 -25
@@ -470,33 +470,17 @@ static bool assoc_array_insert_in_empty_tree(struct assoc_array_edit *edit) }/* -* Handle insertion into a terminal node. +* Insert into a terminal node without changing its shape, if that can be +* done: in place of a leaf with the same index key, or in a free slot. */ -static bool assoc_array_insert_into_terminal_node (struct assoc_array_edit *edit, -const struct assoc_array_ops *ops, -const void *index_key, -struct assoc_array_walk_result *result) +static bool assoc_array_insert_in_node (struct assoc_array_edit *edit, +const struct assoc_array_ops *ops, +const void *index_key, +struct assoc_array_node *node) { -struct assoc_array_shortcut *shortcut, *new_s0; -struct assoc_array_node *node, *new_n0, *new_n1, *side;struct assoc_array_ptr *ptr; -unsigned long dissimilarity, base_seg, blank; -size_t keylen; -bool have_meta; -int level, diff; -int slot, next_slot, free_slot, i, j; - - node = result->terminal_node.node; - level = result->terminal_node.level; - edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot; - -pr_devel ("-->%s()\n" , __func__); +int free_slot, i; -/* We arrived at a node which doesn't have an onward node or shortcut -* pointer that we have to follow. This means that (a) the leaf we -* want must go here (either by insertion or replacement) or (b) we -* need to split this node and insert in one of the fragments. -*/ free_slot =-1 ;/* Firstly, we have to check the leaves in this node to see if there's
@@ -514,7 +498,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,pr_devel ("replace in slot %d\n" , i); edit->leaf_p = &node->slots[i]; edit->dead_leaf = node->slots[i]; -pr_devel ("<--%s() = ok [replace]\n" , __func__);return true; } }
@@ -526,7 +509,42 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,pr_devel ("insert in free slot %d\n" , free_slot); edit->leaf_p = &node->slots[free_slot]; edit->adjust_count_on = node; -pr_devel ("<--%s() = ok [insert]\n" , __func__); +return true; + } + +return false; +} + +/* +* Handle insertion into a terminal node. +*/ +static bool assoc_array_insert_into_terminal_node (struct assoc_array_edit *edit, +const struct assoc_array_ops *ops, +const void *index_key, +struct assoc_array_walk_result *result) +{ +struct assoc_array_shortcut *shortcut, *new_s0; +struct assoc_array_node *node, *new_n0, *new_n1, *side; +struct assoc_array_ptr *ptr; +unsigned long dissimilarity, base_seg, blank; +size_t keylen; +bool have_meta; +int level, diff; +int slot, next_slot, free_slot, i, j; + + node = result->terminal_node.node; + level = result->terminal_node.level; + edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot; + +pr_devel ("-->%s()\n" , __func__); + +/* We arrived at a node which doesn't have an onward node or shortcut +* pointer that we have to follow. This means that (a) the leaf we +* want must go here (either by insertion or replacement) or (b) we +* need to split this node and insert in one of the fragments. +*/ +if (assoc_array_insert_in_node (edit, ops, index_key, node)) { +pr_devel ("<--%s() = ok [in node]\n" , __func__);return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1853/3318 assoc_array: fill the segment cache in one place
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 1159eaf9acb3de1417fb86b382b5e41b46eb17a4 ]
The loop that records the segment of each leaf in a full node is written out twice in assoc_array_insert_into_terminal_node(): for the node at its own level, and again at the far end of a shortcut that replaces it. Make it assoc_array_fill_segment_cache().
The second copy did not look for metadata pointers, because that path is only taken for a node holding nothing but leaves, so the function finds none there. The new key's segment is still set by each caller, from the walk the first time and from the key the second.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 56 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 21 deletions(-)
lib/assoc_array.c +35 -21
@@ -515,6 +515,38 @@ static bool assoc_array_insert_in_node(struct assoc_array_edit *edit,return false; } +/* +* Fill in the edit script's segment cache for a full node: the segment at +* this level of each leaf's index key, or 0xff for a metadata pointer. +* The new key's segment, in the last entry, is left to the caller. Returns +* true if there are any metadata pointers. +*/ +static bool assoc_array_fill_segment_cache (struct assoc_array_edit *edit, +const struct assoc_array_ops *ops, +const struct assoc_array_node *node, +int level) +{ +struct assoc_array_ptr *ptr; +unsigned long base_seg; +bool have_meta; +int i; + + have_meta = false; +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { + ptr = node->slots[i]; +if (assoc_array_ptr_is_meta (ptr)) { + edit->segment_cache[i] =0xff ; + have_meta = true; +continue ; + } + base_seg = ops->get_object_key_chunk ( +assoc_array_ptr_to_leaf (ptr), level); + base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; + edit->segment_cache[i] = base_seg &ASSOC_ARRAY_FAN_MASK ; + } +return have_meta; +} +/* * Handle insertion into a terminal node. */
@@ -534,7 +566,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, node = result->terminal_node.node; level = result->terminal_node.level; - edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot;pr_devel ("-->%s()\n" , __func__);
@@ -566,19 +597,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,/* We need to find out how similar the leaves are. */ pr_devel ("no spare slots\n" ); - have_meta = false; -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { - ptr = node->slots[i]; -if (assoc_array_ptr_is_meta (ptr)) { - edit->segment_cache[i] =0xff ; - have_meta = true; -continue ; - } - base_seg = ops->get_object_key_chunk ( -assoc_array_ptr_to_leaf (ptr), level); - base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; - edit->segment_cache[i] = base_seg &ASSOC_ARRAY_FAN_MASK ; - } + have_meta =assoc_array_fill_segment_cache (edit, ops, node, level); + edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot;if (have_meta) {pr_devel ("have meta\n" );
@@ -791,13 +811,7 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,/* This now reduces to a node splitting exercise for which we'll need * to regenerate the disparity table. */ -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { - ptr = node->slots[i]; - base_seg = ops->get_object_key_chunk (assoc_array_ptr_to_leaf (ptr), - level); - base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; - edit->segment_cache[i] = base_seg &ASSOC_ARRAY_FAN_MASK ; - } +assoc_array_fill_segment_cache (edit, ops, node, level); base_seg = ops->get_key_chunk (index_key, level); base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1854/3318 assoc_array: move node splitting into a function of its own
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 3c99a07bc82b051771ce0eb69274aceb9abf1eb7 ]
Move the code after the do_split_node label into assoc_array_split_node(), which both the split path and the shortcut path still reach through that label.
It sets new_n1's back pointer itself, which both paths did before jumping there, and it no longer sets new_n1's parent slot to -1 first:
it always sets the real one.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 194 +++++++++++++++++++++++++--------------------- 1 file changed, 104 insertions(+), 90 deletions(-)
lib/assoc_array.c +104 -90
@@ -547,6 +547,106 @@ static bool assoc_array_fill_segment_cache(struct assoc_array_edit *edit,return have_meta; } +/* +* Split a full node into new_n0, which takes its place, and new_n1, below +* new_n0 in the slot of a segment that at least two of the leaves share, +* the new one included. The caller has filled in the segment cache and +* set new_n0's back pointer and parent slot. +*/ +static void assoc_array_split_node (struct assoc_array_edit *edit, +struct assoc_array_node *node, +struct assoc_array_node *new_n0, +struct assoc_array_node *new_n1) +{ +struct assoc_array_shortcut *shortcut; +struct assoc_array_node *side; +struct assoc_array_ptr *ptr; +int slot, next_slot, free_slot, i, j; + +pr_devel ("split node\n" ); + + new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); + new_n0->nr_leaves_on_branch = node->nr_leaves_on_branch; + new_n1->nr_leaves_on_branch =0 ; + +/* Begin by finding two matching leaves. There have to be at least two +* that match - even if there are meta pointers - because any leaf that +* would match a slot with a meta pointer in it must be somewhere +* behind that meta pointer and cannot be here. Further, given N +* remaining leaf slots, we now have N+1 leaves to go in them. +*/ +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { + slot = edit->segment_cache[i]; +if (slot !=0xff ) +for (j = i +1 ; j <ASSOC_ARRAY_FAN_OUT +1 ; j++) +if (edit->segment_cache[j] == slot) + goto found_slot_for_multiple_occupancy; + } +found_slot_for_multiple_occupancy: +pr_devel ("same slot: %x %x [%02x]\n" , i, j, slot); +BUG_ON (i >=ASSOC_ARRAY_FAN_OUT ); +BUG_ON (j >=ASSOC_ARRAY_FAN_OUT +1 ); +BUG_ON (slot >=ASSOC_ARRAY_FAN_OUT ); + + new_n1->parent_slot = slot; + +/* Metadata pointers cannot change slot */ +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) +if (assoc_array_ptr_is_meta (node->slots[i])) + new_n0->slots[i] = node->slots[i]; +else + new_n0->slots[i] =NULL ; +BUG_ON (new_n0->slots[slot] !=NULL ); + new_n0->slots[slot] =assoc_array_node_to_ptr (new_n1); + +/* Filter the leaf pointers between the new nodes */ + free_slot =-1 ; + next_slot =0 ; +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +if (assoc_array_ptr_is_meta (node->slots[i])) +continue ; +if (edit->segment_cache[i] == slot) { + new_n1->slots[next_slot++] = node->slots[i]; + new_n1->nr_leaves_on_branch++; + }else { +do { + free_slot++; + }while (new_n0->slots[free_slot] !=NULL ); + new_n0->slots[free_slot] = node->slots[i]; + } + } + +pr_devel ("filtered: f=%x n=%x\n" , free_slot, next_slot); + +if (edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] != slot) { +do { + free_slot++; + }while (new_n0->slots[free_slot] !=NULL ); + edit->leaf_p = &new_n0->slots[free_slot]; + edit->adjust_count_on = new_n0; + }else { + edit->leaf_p = &new_n1->slots[next_slot++]; + edit->adjust_count_on = new_n1; + } + +BUG_ON (next_slot <=1 ); + + edit->set_backpointers_to =assoc_array_node_to_ptr (new_n0); +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +if (edit->segment_cache[i] ==0xff ) { + ptr = node->slots[i]; +BUG_ON (assoc_array_ptr_is_leaf (ptr)); +if (assoc_array_ptr_is_node (ptr)) { + side =assoc_array_ptr_to_node (ptr); + edit->set_backpointers[i] = &side->back_pointer; + }else { + shortcut =assoc_array_ptr_to_shortcut (ptr); + edit->set_backpointers[i] = &shortcut->back_pointer; + } + } + } +} +/* * Handle insertion into a terminal node. */
@@ -555,14 +655,14 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,const void *index_key, struct assoc_array_walk_result *result) { - struct assoc_array_shortcut *shortcut, *new_s0; -struct assoc_array_node *node, *new_n0, *new_n1, *side; + struct assoc_array_shortcut *new_s0; +struct assoc_array_node *node, *new_n0, *new_n1;struct assoc_array_ptr *ptr;unsigned long dissimilarity, base_seg, blank;size_t keylen;bool have_meta;int level, diff; -int slot, next_slot, free_slot, i, j; +int i; node = result->terminal_node.node; level = result->terminal_node.level;
@@ -632,8 +732,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, } split_node: -pr_devel ("split node\n" ); -/* We need to split the current node. The node must contain anything * from a single leaf (in the one leaf case, this leaf will cluster * with the new leaf) and the rest meta-pointers, to all leaves, some
@@ -652,91 +750,9 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer = node->back_pointer; new_n0->parent_slot = node->parent_slot; - new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); - new_n1->parent_slot =-1 ;/* Need to calculate this */ do_split_node: -pr_devel ("do_split_node\n" ); - - new_n0->nr_leaves_on_branch = node->nr_leaves_on_branch; - new_n1->nr_leaves_on_branch =0 ; - -/* Begin by finding two matching leaves. There have to be at least two -* that match - even if there are meta pointers - because any leaf that -* would match a slot with a meta pointer in it must be somewhere -* behind that meta pointer and cannot be here. Further, given N -* remaining leaf slots, we now have N+1 leaves to go in them. -*/ -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { - slot = edit->segment_cache[i]; -if (slot !=0xff ) -for (j = i +1 ; j <ASSOC_ARRAY_FAN_OUT +1 ; j++) -if (edit->segment_cache[j] == slot) - goto found_slot_for_multiple_occupancy; - } -found_slot_for_multiple_occupancy: -pr_devel ("same slot: %x %x [%02x]\n" , i, j, slot); -BUG_ON (i >=ASSOC_ARRAY_FAN_OUT ); -BUG_ON (j >=ASSOC_ARRAY_FAN_OUT +1 ); -BUG_ON (slot >=ASSOC_ARRAY_FAN_OUT ); - - new_n1->parent_slot = slot; - -/* Metadata pointers cannot change slot */ -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) -if (assoc_array_ptr_is_meta (node->slots[i])) - new_n0->slots[i] = node->slots[i]; -else - new_n0->slots[i] =NULL ; -BUG_ON (new_n0->slots[slot] !=NULL ); - new_n0->slots[slot] =assoc_array_node_to_ptr (new_n1); - -/* Filter the leaf pointers between the new nodes */ - free_slot =-1 ; - next_slot =0 ; -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -if (assoc_array_ptr_is_meta (node->slots[i])) -continue ; -if (edit->segment_cache[i] == slot) { - new_n1->slots[next_slot++] = node->slots[i]; - new_n1->nr_leaves_on_branch++; - }else { -do { - free_slot++; - }while (new_n0->slots[free_slot] !=NULL ); - new_n0->slots[free_slot] = node->slots[i]; - } - } - -pr_devel ("filtered: f=%x n=%x\n" , free_slot, next_slot); - -if (edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] != slot) { -do { - free_slot++; - }while (new_n0->slots[free_slot] !=NULL ); - edit->leaf_p = &new_n0->slots[free_slot]; - edit->adjust_count_on = new_n0; - }else { - edit->leaf_p = &new_n1->slots[next_slot++]; - edit->adjust_count_on = new_n1; - } - -BUG_ON (next_slot <=1 ); - - edit->set_backpointers_to =assoc_array_node_to_ptr (new_n0); -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -if (edit->segment_cache[i] ==0xff ) { - ptr = node->slots[i]; -BUG_ON (assoc_array_ptr_is_leaf (ptr)); -if (assoc_array_ptr_is_node (ptr)) { - side =assoc_array_ptr_to_node (ptr); - edit->set_backpointers[i] = &side->back_pointer; - }else { - shortcut =assoc_array_ptr_to_shortcut (ptr); - edit->set_backpointers[i] = &shortcut->back_pointer; - } - } - } +assoc_array_split_node (edit, node, new_n0, new_n1); ptr = node->back_pointer;if (!ptr)
@@ -791,8 +807,6 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, new_s0->next_node =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); new_n0->parent_slot =0 ; - new_n1->back_pointer =assoc_array_node_to_ptr (new_n0); - new_n1->parent_slot =-1 ;/* Need to calculate this */ new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ;pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1855/3318 assoc_array: move shortcut creation into a function of its own
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit fdc6124c55dd0c5aa8e3ec30e6425b4d423ada24 ]
Move the code after the all_leaves_cluster_together label into assoc_array_insert_shortcut(), which returns the new shortcut, or NULL when it cannot allocate one. The caller installs it and jumps to do_split_node as before.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 146 ++++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 64 deletions(-)
lib/assoc_array.c +82 -64
@@ -647,6 +647,84 @@ static void assoc_array_split_node(struct assoc_array_edit *edit, } } +/* +* All the leaves, new and old, want to cluster together in this node in the +* same slot, so we have to replace this node with a shortcut to skip over +* the identical parts of the key, leading to new_n0. The caller then splits +* the leaves between new_n0 and new_n1 at the shortcut's far end, for which +* this fills in the segment cache. +*/ +static struct assoc_array_shortcut * +assoc_array_insert_shortcut (struct assoc_array_edit *edit, +const struct assoc_array_ops *ops, +const void *index_key, +struct assoc_array_node *node,int level, +struct assoc_array_node *new_n0) +{ +struct assoc_array_shortcut *new_s0; +unsigned long base_seg, blank; +size_t keylen; +int diff, i; + +/* Firstly we need to work out where the leaves start diverging as a +* bit position into their keys so that we know how big the shortcut +* needs to be. +* +* We only need to make a single pass of N of the N+1 leaves because if +* any keys differ between themselves at bit X then at least one of +* them must also differ with the base key at bit X or before. +*/ +pr_devel ("all leaves cluster together\n" ); + diff =INT_MAX ; +for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { +int x = ops->diff_objects (assoc_array_ptr_to_leaf (node->slots[i]), + index_key); +if (x < diff) { +BUG_ON (x <0 ); + diff = x; + } + } +BUG_ON (diff ==INT_MAX ); +BUG_ON (diff < level +ASSOC_ARRAY_LEVEL_STEP ); + + keylen =round_up (diff,ASSOC_ARRAY_KEY_CHUNK_SIZE ); + keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; + + new_s0 =kzalloc (struct_size (new_s0, index_key, keylen),GFP_KERNEL ); +if (!new_s0) +return NULL ; + edit->new_meta[2 ] =assoc_array_shortcut_to_ptr (new_s0); + + new_s0->back_pointer = node->back_pointer; + new_s0->parent_slot = node->parent_slot; + new_s0->next_node =assoc_array_node_to_ptr (new_n0); + new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); + new_n0->parent_slot =0 ; + + new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ; +pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff); +BUG_ON (level <=0 ); + +for (i =0 ; i < keylen; i++) + new_s0->index_key[i] = + ops->get_key_chunk (index_key, i *ASSOC_ARRAY_KEY_CHUNK_SIZE ); + +if (level &ASSOC_ARRAY_KEY_CHUNK_MASK ) { + blank =ULONG_MAX << (level &ASSOC_ARRAY_KEY_CHUNK_MASK ); +pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , level, blank); + new_s0->index_key[keylen -1 ] &= ~blank; + } + +/* This now reduces to a node splitting exercise for which we'll need +* to regenerate the disparity table. +*/ +assoc_array_fill_segment_cache (edit, ops, node, level); + base_seg = ops->get_key_chunk (index_key, level); + base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; + edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = base_seg &ASSOC_ARRAY_FAN_MASK ; +return new_s0; +} +/* * Handle insertion into a terminal node. */
@@ -658,10 +736,9 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,struct assoc_array_shortcut *new_s0;struct assoc_array_node *node, *new_n0, *new_n1;struct assoc_array_ptr *ptr; -unsigned long dissimilarity, base_seg, blank; -size_t keylen; +unsigned long dissimilarity, base_seg;bool have_meta; -int level, diff; +int level;int i; node = result->terminal_node.node;
@@ -766,70 +843,11 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,return true; all_leaves_cluster_together: -/* All the leaves, new and old, want to cluster together in this node -* in the same slot, so we have to replace this node with a shortcut to -* skip over the identical parts of the key and then place a pair of -* nodes, one inside the other, at the end of the shortcut and -* distribute the keys between them. -* -* Firstly we need to work out where the leaves start diverging as a -* bit position into their keys so that we know how big the shortcut -* needs to be. -* -* We only need to make a single pass of N of the N+1 leaves because if -* any keys differ between themselves at bit X then at least one of -* them must also differ with the base key at bit X or before. -*/ -pr_devel ("all leaves cluster together\n" ); - diff =INT_MAX ; -for (i =0 ; i <ASSOC_ARRAY_FAN_OUT ; i++) { -int x = ops->diff_objects (assoc_array_ptr_to_leaf (node->slots[i]), - index_key); -if (x < diff) { -BUG_ON (x <0 ); - diff = x; - } - } -BUG_ON (diff ==INT_MAX ); -BUG_ON (diff < level +ASSOC_ARRAY_LEVEL_STEP ); - - keylen =round_up (diff,ASSOC_ARRAY_KEY_CHUNK_SIZE ); - keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; - - new_s0 =kzalloc (struct_size (new_s0, index_key, keylen),GFP_KERNEL ); + new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, + node, level, new_n0);if (!new_s0)return false; - edit->new_meta[2 ] =assoc_array_shortcut_to_ptr (new_s0); - edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); - new_s0->back_pointer = node->back_pointer; - new_s0->parent_slot = node->parent_slot; - new_s0->next_node =assoc_array_node_to_ptr (new_n0); - new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); - new_n0->parent_slot =0 ; - - new_s0->skip_to_level = level = diff & ~ASSOC_ARRAY_LEVEL_STEP_MASK ; -pr_devel ("skip_to_level = %d [diff %d]\n" , level, diff); -BUG_ON (level <=0 ); - -for (i =0 ; i < keylen; i++) - new_s0->index_key[i] = - ops->get_key_chunk (index_key, i *ASSOC_ARRAY_KEY_CHUNK_SIZE ); - -if (level &ASSOC_ARRAY_KEY_CHUNK_MASK ) { - blank =ULONG_MAX << (level &ASSOC_ARRAY_KEY_CHUNK_MASK ); -pr_devel ("blank off [%zu] %d: %lx\n" , keylen -1 , level, blank); - new_s0->index_key[keylen -1 ] &= ~blank; - } - -/* This now reduces to a node splitting exercise for which we'll need -* to regenerate the disparity table. -*/ -assoc_array_fill_segment_cache (edit, ops, node, level); - - base_seg = ops->get_key_chunk (index_key, level); - base_seg >>= level &ASSOC_ARRAY_KEY_CHUNK_MASK ; - edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = base_seg &ASSOC_ARRAY_FAN_MASK ; goto do_split_node; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1856/3318 assoc_array: choose between splitting a node and a shortcut without gotos
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit c47aee71e14dd28d39fce95af83166d7a28a5f2b ]
With its jobs in functions, assoc_array_insert_into_terminal_node() comes down to one decision: replace the node with a shortcut when every leaf in it and the new key share one segment, or split it otherwise. Write that as an if and an else, in place of the labels split_node, do_split_node and all_leaves_cluster_together.
Each branch now works out where its replacement goes from that replacement's own back pointer and parent slot, with assoc_array_parent_link(), rather than both using the node's. The two are the same today.
None of the new functions is recursive, and gcc inlines all of them into assoc_array_insert(), whose stack frame is 240 bytes after this series against 224 before it, on an x86-64 defconfig.
No functional change.
Stable-dep-of: 48691075b0ad ("assoc_array: don't chain a new shortcut onto an existing one")
--- lib/assoc_array.c | 127 ++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 66 deletions(-)
lib/assoc_array.c +61 -66
@@ -469,6 +469,21 @@ static bool assoc_array_insert_in_empty_tree(struct assoc_array_edit *edit)return true; } +/* +* The pointer that leads to a node or shortcut with the given back pointer +* and parent slot: the root, a slot in a node, or a shortcut's next node. +*/ +static struct assoc_array_ptr **assoc_array_parent_link (struct assoc_array *array, +struct assoc_array_ptr *back_pointer, +int parent_slot) +{ +if (!back_pointer) +return &array->root; +if (assoc_array_ptr_is_node (back_pointer)) +return &assoc_array_ptr_to_node (back_pointer)->slots[parent_slot]; +return &assoc_array_ptr_to_shortcut (back_pointer)->next_node; +} +/* * Insert into a terminal node without changing its shape, if that can be * done: in place of a leaf with the same index key, or in a free slot.
@@ -547,6 +562,20 @@ static bool assoc_array_fill_segment_cache(struct assoc_array_edit *edit,return have_meta; } +/* +* Whether the leaves of a full node and the new key all share one segment, +* so that splitting the node cannot make room. +*/ +static bool assoc_array_all_one_segment (const struct assoc_array_edit *edit) +{ +int i; + +for (i =1 ; i <ASSOC_ARRAY_FAN_OUT +1 ; i++) +if (edit->segment_cache[i] != edit->segment_cache[0 ]) +return false; +return true; +} +/* * Split a full node into new_n0, which takes its place, and new_n1, below * new_n0 in the slot of a segment that at least two of the leaves share,
@@ -735,11 +764,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, {struct assoc_array_shortcut *new_s0;struct assoc_array_node *node, *new_n0, *new_n1; -struct assoc_array_ptr *ptr; -unsigned long dissimilarity, base_seg;bool have_meta;int level; -int i; node = result->terminal_node.node; level = result->terminal_node.level;
@@ -777,78 +803,47 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit, have_meta =assoc_array_fill_segment_cache (edit, ops, node, level); edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] = result->terminal_node.slot; -if (have_meta) { -pr_devel ("have meta\n" ); - goto split_node; - } - -/* The node contains only leaves */ - dissimilarity =0 ; - base_seg = edit->segment_cache[0 ]; -for (i =1 ; i <ASSOC_ARRAY_FAN_OUT ; i++) - dissimilarity |= edit->segment_cache[i] ^ base_seg; - -pr_devel ("only leaves; dissimilarity=%lx\n" , dissimilarity); - -if ((dissimilarity &ASSOC_ARRAY_FAN_MASK ) ==0 ) { -/* The old leaves all cluster in the same slot. We will need -* to insert a shortcut if the new node wants to cluster with them. +if (!have_meta &&assoc_array_all_one_segment (edit)) { +/* The node only contains leaves and all the leaves cluster in +* the same slot, so we need to insert a shortcut to skip the +* common portion of the key and split the node at the +* shortcut's far end. */ -if ((edit->segment_cache[ASSOC_ARRAY_FAN_OUT ] ^ base_seg) ==0 ) - goto all_leaves_cluster_together; - -/* Otherwise all the old leaves cluster in the same slot, but -* the new leaf wants to go into a different slot - so we -* create a new node (n0) to hold the new leaf and a pointer to -* a new node (n1) holding all the old leaves. + new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, + node, level, new_n0); +if (!new_s0) +return false; + edit->set[0 ].ptr =assoc_array_parent_link (edit->array, + new_s0->back_pointer, + new_s0->parent_slot); + edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); + }else { +/* We need to split the current node. The node must contain +* anything from a single leaf (in the one leaf case, this leaf +* will cluster with the new leaf) and the rest meta-pointers, +* to all leaves, some of which may cluster. +* +* We need to expel at least two leaves out of a set consisting +* of the leaves in the node and the new leaf. The current meta +* pointers can just be copied as they shouldn't cluster with +* any of the leaves. If all the old leaves cluster in one slot +* and the new leaf does not, they all go and the new leaf stays. * -* This can be done by falling through to the node splitting -* path. +* We need a new node (n0) to replace the current one and a new +* node to take the expelled nodes (n1). */ -pr_devel ("present leaves cluster but not new leaf\n" ); + new_n0->back_pointer = node->back_pointer; + new_n0->parent_slot = node->parent_slot; + edit->set[0 ].ptr =assoc_array_parent_link (edit->array, + new_n0->back_pointer, + new_n0->parent_slot); + edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); } -split_node: -/* We need to split the current node. The node must contain anything -* from a single leaf (in the one leaf case, this leaf will cluster -* with the new leaf) and the rest meta-pointers, to all leaves, some -* of which may cluster. -* -* It won't contain the case in which all the current leaves plus the -* new leaves want to cluster in the same slot. -* -* We need to expel at least two leaves out of a set consisting of the -* leaves in the node and the new leaf. The current meta pointers can -* just be copied as they shouldn't cluster with any of the leaves. -* -* We need a new node (n0) to replace the current one and a new node to -* take the expelled nodes (n1). -*/ - edit->set[0 ].to =assoc_array_node_to_ptr (new_n0); - new_n0->back_pointer = node->back_pointer; - new_n0->parent_slot = node->parent_slot; - -do_split_node:assoc_array_split_node (edit, node, new_n0, new_n1); - - ptr = node->back_pointer; -if (!ptr) - edit->set[0 ].ptr = &edit->array->root; -else if (assoc_array_ptr_is_node (ptr)) - edit->set[0 ].ptr = &assoc_array_ptr_to_node (ptr)->slots[node->parent_slot]; -else - edit->set[0 ].ptr = &assoc_array_ptr_to_shortcut (ptr)->next_node; edit->excised_meta[0 ] =assoc_array_node_to_ptr (node);pr_devel ("<--%s() = ok [split node]\n" , __func__);return true; - -all_leaves_cluster_together: - new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, - node, level, new_n0); -if (!new_s0) -return false; - edit->set[0 ].to =assoc_array_shortcut_to_ptr (new_s0); - goto do_split_node; }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1857/3318 assoc_array: dont chain a new shortcut onto an existing one
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 48691075b0adc590a6831390723e3603dfca76fc ]
When a full node's leaves and the new key all share the node's segment, assoc_array_insert_into_terminal_node() replaces the node with a shortcut to a pair of new nodes. If the node is itself the target of a shortcut, the new shortcut is installed as that shortcut's next node, and a shortcut leading to a shortcut is something nothing expects:assoc_array_walk() indexes the second one as a node, and assoc_array_apply_edit() hits the BUG_ON() in the loop that adjusts nr_leaves_on_branch, on that same insertion.
Deletion gets a node there. When the subtree below a shortcut shrinks enough, assoc_array_delete() collapses it into one node below the shortcut, and the leaves it collects can all share that node's segment. The next key that shares it too takes this path. Eighteen insertions and a deletion are enough: sixteen keys that agree on bits 0-11, one that leaves them at bit 8 and is deleted again, and one more that agrees with the sixteen.
Have the new shortcut replace the one in front of the node as well. assoc_array_insert_shortcut() gives it that shortcut's back pointer and parent slot, so the caller installs it where that one was, and excises the old shortcut along with the node, which takes a second entry in excised_meta[]. The new shortcut's index key comes from the new key up to the new skip level, so it covers what the old one did.
Found by a userspace test doing random insertions and deletions on keys that share long prefixes; a targeted case builds a shortcut, deletes down to the collapse and inserts one more key.
--- include/linux/assoc_array_priv.h | 2 +- lib/assoc_array.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)
include/linux/assoc_array_priv.h +1 -1
@@ -80,7 +80,7 @@ struct assoc_array_edit {struct assoc_array_ptr **leaf_p;struct assoc_array_ptr *dead_leaf;struct assoc_array_ptr *new_meta[3 ]; -struct assoc_array_ptr *excised_meta[1 ]; +struct assoc_array_ptr *excised_meta[2 ];struct assoc_array_ptr *excised_subtree;struct assoc_array_ptr **set_backpointers[ASSOC_ARRAY_FAN_OUT ];struct assoc_array_ptr *set_backpointers_to;
lib/assoc_array.c +20 -4
@@ -679,9 +679,10 @@ static void assoc_array_split_node(struct assoc_array_edit *edit,/* * All the leaves, new and old, want to cluster together in this node in the * same slot, so we have to replace this node with a shortcut to skip over -* the identical parts of the key, leading to new_n0. The caller then splits -* the leaves between new_n0 and new_n1 at the shortcut's far end, for which -* this fills in the segment cache. +* the identical parts of the key, leading to new_n0. If the node is the +* target of a shortcut, the new one replaces that shortcut as well. The +* caller then splits the leaves between new_n0 and new_n1 at the shortcut's +* far end, for which this fills in the segment cache. */ static struct assoc_array_shortcut * assoc_array_insert_shortcut(struct assoc_array_edit *edit,
@@ -726,6 +727,20 @@ assoc_array_insert_shortcut(struct assoc_array_edit *edit, new_s0->back_pointer = node->back_pointer; new_s0->parent_slot = node->parent_slot; + +/* A shortcut has to lead to a node, so a node at the end of a shortcut +* is replaced together with that shortcut. The new one holds the index +* key from the root, so it covers what the old one did. +*/ +if (node->back_pointer && +assoc_array_ptr_is_shortcut (node->back_pointer)) { +struct assoc_array_shortcut *above = +assoc_array_ptr_to_shortcut (node->back_pointer); + + new_s0->back_pointer = above->back_pointer; + new_s0->parent_slot = above->parent_slot; + edit->excised_meta[1 ] = node->back_pointer; + } new_s0->next_node =assoc_array_node_to_ptr (new_n0); new_n0->back_pointer =assoc_array_shortcut_to_ptr (new_s0); new_n0->parent_slot =0 ;
@@ -807,7 +822,8 @@ static bool assoc_array_insert_into_terminal_node(struct assoc_array_edit *edit,/* The node only contains leaves and all the leaves cluster in * the same slot, so we need to insert a shortcut to skip the * common portion of the key and split the node at the -* shortcut's far end. +* shortcut's far end. The shortcut goes wherever its back +* pointer says, which may be further up than the node. */ new_s0 =assoc_array_insert_shortcut (edit, ops, index_key, node, level, new_n0);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1858/3318 assoc_array: keep gcs cleanup out of the live tree on allocation failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
[ Upstream commit 8afff2e4b90978b8203f9e3898995dcf86821b49 ]
assoc_array_gc() builds a copy of the tree. Where the copy reaches a shortcut, it allocates the copy of the shortcut with kmalloc_flex(), fills it with memcpy(), links it into the new tree, and only then allocates the copy of the node after it. The memcpy() leaves the new shortcut's next_node pointing at the old tree's node, so if that second allocation fails, the cleanup, assoc_array_destroy_subtree() on the new tree, follows the new shortcut into the old tree, and the BUG_ON() on the old node's back pointer fires.
Allocate the node first, and the shortcut once the node exists, freeing the node again if the shortcut cannot be allocated. A copied shortcut is then only linked into the new tree when the copy of its node is there to follow it. Nothing else changes: with no allocation failing, the trees gc builds are the same as before.
Found by a userspace test that makes each allocation of each operation fail in turn.
--- lib/assoc_array.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
lib/assoc_array.c +12 -7
@@ -1562,17 +1562,26 @@ int assoc_array_gc(struct assoc_array *array, cursor = array->root; descend: -/* If this point is a shortcut, then we need to duplicate it and -* advance the target cursor. +/* The node at this position is duplicated, and so is the shortcut in +* front of it if there is one. The node is allocated first: the copy +* of the shortcut starts out pointing at the old node, and must not be +* in the new tree if the node cannot be allocated, or the cleanup +* would follow it into the old tree. */ + new_n =kzalloc (sizeof (struct assoc_array_node ),GFP_KERNEL ); +if (!new_n) + goto enomem; +if (assoc_array_ptr_is_shortcut (cursor)) { shortcut =assoc_array_ptr_to_shortcut (cursor); keylen =round_up (shortcut->skip_to_level,ASSOC_ARRAY_KEY_CHUNK_SIZE ); keylen >>=ASSOC_ARRAY_KEY_CHUNK_SHIFT ; new_s =kmalloc (struct_size (new_s, index_key, keylen),GFP_KERNEL ); -if (!new_s) +if (!new_s) { +kfree (new_n); goto enomem; + }pr_devel ("dup shortcut %p -> %p\n" , shortcut, new_s);memcpy (new_s, shortcut,struct_size (new_s, index_key, keylen)); new_s->back_pointer = new_parent;
@@ -1582,11 +1591,7 @@ int assoc_array_gc(struct assoc_array *array, cursor = shortcut->next_node; } -/* Duplicate the node at this position */ node =assoc_array_ptr_to_node (cursor); - new_n =kzalloc (sizeof (struct assoc_array_node ),GFP_KERNEL ); -if (!new_n) - goto enomem;pr_devel ("dup node %p -> %p\n" , node, new_n); new_n->back_pointer = new_parent; new_n->parent_slot = node->parent_slot;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1859/3318 KVM: nSVM: Check validity of vmcs01 save area copied from SMRAM on RSM
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 053621535f014085c935879582dd3b65964a0dce ]
When doing RSM to L2, validate L1's state after copying it back into vmcb01 from SMRAM, as SMRAM is carved out of guest memory, i.e. is writable by the guest. Failure to validate L1's state is especially problematic for inputs to MMU context, as KVM can end up with impossible CR4 vs. EFER state. E.g. without the recent hardening FNAME(walk_addr_generic), a guest can trigger:
------------[ cut here ]------------ UBSAN: array-index-out-of-bounds in arch/x86/kvm/mmu/paging_tmpl.h:435:15 index 3 is out of range for type 'u32 [2]' CPU: 3 UID: 0 PID: 92 Comm: CPU 1/KVM Not tainted 7.3.0-rc1 #2 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x5f/0x90 dump_stack+0x10/0x18 ubsan_epilogue+0x9/0x39 __ubsan_handle_out_of_bounds.cold+0x50/0x55 paging32_walk_addr_generic+0x889/0x970 paging32_page_fault+0x79/0xa60 kvm_mmu_do_page_fault+0x125/0x270 kvm_mmu_page_fault+0x88/0x7b0 npf_interception+0xc8/0x220 [kvm_amd] svm_invoke_exit_handler+0x16d/0x1d0 [kvm_amd] svm_handle_exit+0xb7/0x160 [kvm_amd] vcpu_enter_guest+0x428/0x16a0 kvm_arch_vcpu_ioctl_run+0x479/0x920 kvm_vcpu_ioctl+0x316/0xb00 __x64_sys_ioctl+0xa3/0x100 x64_sys_call+0x281/0x23d0 do_syscall_64+0xba/0x550 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x79bb30deb04b </TASK> ---[ end trace ]---
Message-ID: <[email protected]>
--- arch/x86/kvm/svm/nested.c | 23 ++++++++++++++++------- arch/x86/kvm/svm/svm.c | 2 ++ arch/x86/kvm/svm/svm.h | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-)
arch/x86/kvm/svm/nested.c +16 -7
@@ -1618,6 +1618,21 @@ static void nested_copy_vmcb_cache_to_control(struct vmcb_control_area *dst,/* 'clean' and 'hv_enlightenments' are not changed by KVM */ } +bool nested_svm_check_vmcb01_save (struct kvm_vcpu *vcpu, +struct vmcb_save_area *save) +{ +struct vmcb_save_area_cached save_cached; + +if (!(save->cr0 &X86_CR0_PG ) || + !(save->cr0 &X86_CR0_PE ) || + (save->rflags &X86_EFLAGS_VM ) || + ((save->efer &EFER_LMA ) && !(save->efer &EFER_LME ))) +return false; + +__nested_copy_vmcb_save_to_cache (&save_cached, save); +return __nested_vmcb_check_save (vcpu, &save_cached); +} +static int svm_get_nested_state (struct kvm_vcpu *vcpu,struct kvm_nested_state __user *user_kvm_nested_state,u32 user_data_size)
@@ -1694,7 +1709,6 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu, &user_kvm_nested_state->data.svm[0 ];struct vmcb_control_area *ctl;struct vmcb_save_area *save; -struct vmcb_save_area_cached save_cached;struct vmcb_ctrl_area_cached ctl_cached;unsigned long cr0;int ret;
@@ -1764,12 +1778,7 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,* Validate host state saved from before VMRUN (see * nested_svm_check_permissions). */ -__nested_copy_vmcb_save_to_cache (&save_cached, save); -if (!(save->cr0 &X86_CR0_PG ) || - !(save->cr0 &X86_CR0_PE ) || - (save->rflags &X86_EFLAGS_VM ) || - ((save->efer &EFER_LMA ) && !(save->efer &EFER_LME )) || - !__nested_vmcb_check_save (vcpu, &save_cached)) +if (!nested_svm_check_vmcb01_save (vcpu, save)) goto out_free;
arch/x86/kvm/svm/svm.c +2 -0
@@ -4868,6 +4868,8 @@ static int svm_leave_smm(struct kvm_vcpu *vcpu, const union kvm_smram *smram)*/ svm_copy_vmrun_state (&svm->vmcb01.ptr->save, map_save.hva +0x400 ); +if (!nested_svm_check_vmcb01_save (vcpu, &svm->vmcb01.ptr->save)) + goto unmap_save;/* * Enter the nested guest now
arch/x86/kvm/svm/svm.h +2 -0
@@ -627,6 +627,8 @@ void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm, struct vmcb_save_area *save);void nested_sync_control_from_vmcb02 (struct vcpu_svm *svm);void nested_vmcb02_compute_g_pat (struct vcpu_svm *svm); +bool nested_svm_check_vmcb01_save (struct kvm_vcpu *vcpu, +struct vmcb_save_area *save);void svm_switch_vmcb (struct vcpu_svm *svm,struct kvm_vmcb_info *target_vmcb);extern struct kvm_x86_nested_ops svm_nested_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1860/3318 inet: frags: limit the truesize of a reassembly queue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3ae20e4697eb969104fe4b1e98a675f0100382b6 ]
The truesize of fragments in a reassembly queue is only bounded by the per netns ipfrag_high_thresh sysctl, which has no upper limit.
inet_frag_reasm_finish() sums the truesize of all fragments in an int. If this sum reaches 2^32, it wraps, and the final sk_wmem_alloc adjustment of the socket owning the reassembled skb can cancel its own reference, leading to a use-after-free of this socket.
This can be triggered from an unprivileged user/network namespace, raising ipfrag_high_thresh and using padded TUN packets, which keep a large truesize after being trimmed by ip_rcv_core().
Track the sum of the truesize of fragments in each queue, and refuse a fragment that would make it bigger than INT_MAX / 2. Callers kill the queue on this error. This bound is far above the needs of legitimate traffic.
--- include/net/inet_frag.h | 9 +++++++++ net/ipv4/inet_fragment.c | 5 +++++ 2 files changed, 14 insertions(+)
include/net/inet_frag.h +9 -0
@@ -79,6 +79,7 @@ struct frag_v6_compare_key {* @tstamp_type: stamp has a mono delivery time (EDT) * @flags: fragment queue flags * @max_size: maximum received fragment size +* @truesize: sum of the truesize of queued fragments * @fqdir: pointer to struct fqdir * @rcu: rcu head for freeing deferall */
@@ -100,6 +101,7 @@ struct inet_frag_queue {u8 tstamp_type;__u8 flags;u16 max_size; +unsigned int truesize;struct fqdir *fqdir;struct rcu_head rcu; };
@@ -171,6 +173,13 @@ extern const u8 ip_frag_ecn_table[16];#define IPFRAG_OK 0#define IPFRAG_DUP 1#define IPFRAG_OVERLAP 2 +#define IPFRAG_TOOBIG 4 + +/* Max sum of the truesize of fragments in a queue. This keeps the sums +* done in inet_frag_reasm_prepare() and inet_frag_reasm_finish() well +* below INT_MAX. Legitimate traffic stays far below this limit. +*/ +#define INET_FRAG_MAX_TRUESIZE (INT_MAX / 2)int inet_frag_queue_insert (struct inet_frag_queue *q,struct sk_buff *skb,int offset,int end); void *inet_frag_reasm_prepare(struct inet_frag_queue *q, struct sk_buff *skb,
net/ipv4/inet_fragment.c +5 -0
@@ -337,6 +337,7 @@ void inet_frag_queue_flush(struct inet_frag_queue *q, q->rb_fragments =RB_ROOT ; q->fragments_tail =NULL ; q->last_run_head =NULL ; + q->truesize =0 ; }EXPORT_SYMBOL (inet_frag_queue_flush);
@@ -441,6 +442,9 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb, {struct sk_buff *last = q->fragments_tail; +if (skb->truesize >INET_FRAG_MAX_TRUESIZE - q->truesize) +return IPFRAG_TOOBIG ; +/* An IP fragment is never a GSO packet, but an untrusted source * (virtio_net_hdr) may have attached GSO metadata to it. Do not let * that reach the reassembled skb, whose head keeps the first
@@ -503,6 +507,7 @@ int inet_frag_queue_insert(struct inet_frag_queue *q, struct sk_buff *skb,FRAG_CB (skb)->ip_defrag_offset = offset; + q->truesize += skb->truesize;return IPFRAG_OK ; }EXPORT_SYMBOL (inet_frag_queue_insert);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1861/3318 mm/hugetlb: fix endless write fault on a leftover uffd bit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit f61e1cf15fb44f9cf89d43d8ef01f926322bb1c4 ]
hugetlb_fault() resolves the uffd bit on a write fault only if the VMA is registered for userfaultfd write protection, and hugetlb_wp() bails out for any entry with the uffd bit set assuming hugetlb_fault() has already resolved it.
When a read-only hugetlb entry with the uffd bit set is mapped in a VMA that is not registered for uffd-wp, a write fault to it never makes progress. If the access comes from the kernel, e.g. read(2) from /dev/zero into such page, the task spins in the page fault handler, ignores SIGKILL and keeps holding the locks taken by the system call.
Such entries should not exist, but an unprivileged user can create them, for example with MADV_DONTNEED of a page protected with UFFDIO_RWPROTECT or with UFFDIO_COPY in MODE_WP racing with UFFDIO_UNREGISTER.
Clear the uffd bit when the VMA is not registered for uffd-wp and let the fault proceed to hugetlb_wp(), like do_wp_page() does for regular pages.
Note that a FOLL_FORCE write to a page protected with UFFDIO_RWPROTECT in a private VMA that was made PROT_NONE now drops the RWP protection of that page.
Original fix generated by an LLM and sent in private by Josef.
--- mm/hugetlb.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
mm/hugetlb.c +24 -14
@@ -6226,23 +6226,33 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, goto out_ptl;/* Handle userfault-wp first, before trying to lock more pages */ -if (userfaultfd_wp (vma) &&huge_pte_uffd_wp (huge_ptep_get (ptep)) && +if (huge_pte_uffd_wp (huge_ptep_get (ptep)) && (flags &FAULT_FLAG_WRITE ) && !huge_pte_write (entry)) { -struct vm_fault vmf = { - .vma = vma, - .address = haddr, - .real_address = address, - .flags = flags, - }; +if (userfaultfd_wp (vma)) { +struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .real_address = address, + .flags = flags, + }; -spin_unlock (ptl); -if (pagecache_folio) { -folio_unlock (pagecache_folio); -folio_put (pagecache_folio); +spin_unlock (ptl); +if (pagecache_folio) { +folio_unlock (pagecache_folio); +folio_put (pagecache_folio); + } +hugetlb_vma_unlock_read (vma); +mutex_unlock (&hugetlb_fault_mutex_table[hash]); +return handle_userfault (&vmf,VM_UFFD_WP ); } -hugetlb_vma_unlock_read (vma); -mutex_unlock (&hugetlb_fault_mutex_table[hash]); -return handle_userfault (&vmf,VM_UFFD_WP ); + +/* +* TODO: fix all cases where uffd PTE bits remain in VMAs that +* are no longer registered with uffd. +*/ + entry =huge_pte_clear_uffd_wp (entry); +set_huge_pte_at (mm, haddr, ptep, entry,huge_page_size (h)); +/* Fallthrough to CoW */ }/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1862/3318 9p/xen: drain response work after unbinding IRQ
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yizhou Zhao <[email protected]>
[ Upstream commit 7b6f2e3c29fb4d76f1e4973280792eabbd526602 ]
commit ea4f1009408e ("9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition") added cancel_work_sync() to keep xen_9pfs_front_free() from freeing a ring while p9_xen_response() is still running.
The work is currently drained before the event channel IRQ is unbound. That leaves a race window where xen_9pfs_front_event_handler() can run after cancel_work_sync() returns and queue p9_xen_response() again. The following unbind_from_irqhandler() synchronizes with the IRQ handler, but it does not cancel work that the handler already queued. The teardown can then free the ring and private data while the response work remains pending, and the worker later dereferences ring->priv and priv->client.
Unbind the event channel IRQ before draining the work. Once the IRQ is unbound, no new response work can be queued by the backend event channel, and cancel_work_sync() waits for any work that was queued before or during the unbind. It is then safe to release the ring resources.
Message-ID: <[email protected]>
--- net/9p/trans_xen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/9p/trans_xen.c +2 -2
@@ -289,12 +289,12 @@ static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv)for (i =0 ; i < priv->num_rings; i++) {struct xen_9pfs_dataring *ring = &priv->rings[i]; -cancel_work_sync (&ring->work); -if (!priv->rings[i].intf)break ;if (priv->rings[i].irq >0 )unbind_from_irqhandler (priv->rings[i].irq, ring); +cancel_work_sync (&ring->work); +if (priv->rings[i].data.in) { for (j = 0; j < (1 << priv->rings[i].intf->ring_order);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1863/3318 ksmbd: revert fsids on durable reconnect and replay failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 539223f18026448f67d33d09719c355b91db7fd0 ]
On a durable handle reconnect or a request replay, smb2_open() switches to the SMB user's fsids before calling ksmbd_vfs_getattr(). If that call fails, the code jumps to err_out2 and skips ksmbd_revert_fsids() at err_out1. The user's credentials then stay installed on the shared ksmbd worker. Later work on that worker, including other users' requests, runs with the first user's fsuid, fsgid and supplementary groups. ksmbd_free_work_struct() also warns, because work->saved_cred is still set.
Jump to err_out1 instead. No path is held at this point, so skipping the path_put() at err_out is correct.
--- fs/smb/server/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +1 -1
@@ -3101,7 +3101,7 @@ int smb2_open(struct ksmbd_work *work) rc =ksmbd_vfs_getattr (&fp->filp->f_path, &stat);if (rc) - goto err_out2; + goto err_out1; goto reconnected_fp; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1864/3318 mm/ksm: fix use of a freed anon_vma at swap-in
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 4c2dec1dce368ad9e9b1814307cb5ef3832fa07e ]
A folio read from a swap slot previously shared by KSM can remain in the swap cache after the process that first mapped it exits. Its anon_vma can then be freed, so ksm_might_need_to_copy() must not dereference it to compare roots.
Doing so can result in some false-positives, resulting in the reverse mapping missing the new folio mapping, preventing migration and reclaim.
SLAB_TYPESAFE_BY_RCU allows individual anon_vma objects to be reused immediately after freeing. A stale pointer can then refer to another anon_vma whose root matches, even though the target VMA is not linked to that anon_vma.
Move the anonymous rmap compatibility checks into folio_anon_rmap_compatible(). Keep the page-index check and compare the folio's anon_vma pointer against the VMA's own anon_vma and root first.
If neither matches, bite the bullet and walk the VMA's anon_vma_chain. The VMA keeps these anon_vmas alive, and finding a match guarantees that reverse mapping can find the new mapping.
Lorenzo Stoakes says in a private discussion:
"This isn't quite equivalent to the existing check.
Every anon_vma in an anon_vma_chain shares the same root, but if you split a VMA then fork both of them like this:
VMA A
/ \ <split>
VMA B VMA C
\ /
root <- anon_vma 1
----^ ^---- <fork>
/ parent \
anon_vma 2 anon_vma 3
| |
VMA D VMA E
VMA's D and E both get their own new
anon_vma's such that:
VMA D: anon_vma 2 -> anon_vma 1 -> root
VMA E: anon_vma 3 -> anon_vma 1 -> root
And if you found a folio referencing anon_vma 2, the existing check:
anon_vma->root == vma->anon-vma->root
Would be true for VMA's B, C, D & E.
However after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain.
Whether or not that could actually happen in practice... 🙂 I don't know.
[...] after your change it'd be true for VMA D only, as it's the only one with anon_vma 2 in its anon_vma_chain. [...] I would [...] say that you are making the test stricter but more correct.
"
If this affects performance when KSM was never even involved, we could just track whether KSM ever merged anything and just skip these checks.
There isn't really a lot we can do otherwise: for mapped folios we might be able to use folio_get_anon_vma(), but for unmapped folios there really is no easy way to see if the anon_vma is still valid.
Document the (confusing) lifetime requirements of folio_anon_vma().
--- mm/ksm.c | 17 ++++++++++++++--- mm/util.c | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-)
mm/ksm.c +14 -3
@@ -2919,9 +2919,20 @@ struct page *ksm_might_need_to_copy(struct page *page,return page;/* no need to copy it */ }else if (!anon_vma) {return page;/* no need to copy it */ - }else if (page->index ==linear_page_index (vma, address) && - anon_vma->root == vma->anon_vma->root) { -return page;/* still no need to copy it */ + }else if (page->index ==linear_page_index (vma, address)) { +struct anon_vma_chain *avc; + +/* +* Careful: anon_vma might have been freed, so we cannot safely +* dereference it. Add a fast path before we walk the anon_vma chain. +*/ +if (anon_vma == vma->anon_vma || anon_vma == vma->anon_vma->root) +return page; + +list_for_each_entry (avc, &vma->anon_vma_chain, same_vma) { +if (avc->anon_vma == anon_vma) +return page; + } }if (PageHWPoison (page))return ERR_PTR (-EHWPOISON );
mm/util.c +13 -0
@@ -764,6 +764,19 @@ void *vcalloc(size_t n, size_t size) }EXPORT_SYMBOL (vcalloc); +/** +* folio_anon_vma - Get a folio's raw anon_vma pointer. +* @folio: The folio. +* +* The returned pointer may be stale for an unmapped folio. The caller +* must ensure the anon_vma stays alive before dereferencing it. A folio +* reference or lock alone is insufficient; use folio_get_anon_vma() when +* the anon_vma's lifetime is not otherwise protected. Note that +* folio_get_anon_vma() is only useful for folios that are still mapped. +* +* Return: The raw anon_vma pointer for an anonymous, non-KSM folio, or +* %NULL otherwise. +*/ struct anon_vma *folio_anon_vma (struct folio *folio) {unsigned long mapping = (unsigned long )folio->mapping;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1865/3318 ksmbd: enforce the read-only share flag when creating a stream
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Bridges <[email protected]>
[ Upstream commit 09139429fab3a5114c18d7c15fb161511d4d66c9 ]
When a share is read-only, smb2_open() rejects opens that would create or truncate a file. Creating a named stream on an existing file with streams_xattr sets neither O_CREAT nor O_TRUNC, so it passes this check, and smb2_set_stream_name_xattr() then creates the stream. On a Time Machine share, opening a missing AFP_AfpInfo stream also writes one. A user who can write a file at the filesystem level can therefore add streams to it through a read-only share.
Do not create a stream or synthesize AFP_AfpInfo when the share is not writable. Existing streams still open normally, and a missing stream opened with FILE_OPEN still returns STATUS_OBJECT_NAME_NOT_FOUND.
--- fs/smb/server/smb2pdu.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/server/smb2pdu.c +3 -0
@@ -2546,6 +2546,9 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,return -EBADF ; } +if (!test_tree_conn_flag (fp->tcon,KSMBD_TREE_CONN_FLAG_WRITABLE )) +return -EACCES ; + rc =ksmbd_vfs_setxattr (idmap, path, xattr_stream_name,NULL ,0 ,0 , false);if (rc <0 )pr_err ("Failed to store XATTR stream name :%d\n" , rc);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1866/3318 selftests/mm: include kselftest.h in vm_util.h
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vernon Yang <[email protected]>
commit d8a866c766ebe34b4371d42f4a3edca200f5e645 upstream.
The 6.6.y backport of commit fdc3bc349794 ("ksm_tests: skip hugepage test when Transparent Hugepages are disabled"), added a KSFT_SKIP return to khugepaged.c, but the prerequisite include from upstream commit d8a866c766eb ("selftests/mm: add commentary about 9pfs bugs") was not backported.
As a result, the selftests/mm build fails:
khugepaged.c:1195:24: error: ‘KSFT_SKIP’ undeclared (first use in this function)
Add the missing include, only the vm_util.h hunk of commit d8a866c766eb ("selftests/mm: add commentary about 9pfs bugs") is needed here.
The remaining hunks depend on commit 32b42970e861 ("selftests/mm: skip gup_longterm tests on weird filesystems") and commit 571a4b62ed63 ("selftests/mm: skip map_populate on weird filesystems"), which are not present in this tree, so we don't need to backport the remaining hunks.
--- tools/testing/selftests/mm/vm_util.h | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/mm/vm_util.h +1 -0
@@ -5,6 +5,7 @@#include <err.h> #include <strings.h> /* ffsl() */ #include <unistd.h> /* _SC_PAGESIZE */ +#include "../kselftest.h" #define BIT_ULL (nr) (1ULL << (nr))#define PM_SOFT_DIRTY BIT_ULL(55)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1867/3318 PCI/AER: Fix memory leak in aer_recover_work_func() when pci_dev is missing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priyank Rathod <[email protected]>
[ Upstream commit d4c842c3af5bc52b3ca0b8a7f116114e43b6ba44 ]
When ACPI APEI/GHES processes PCIe AER error records, it allocates memory for aer_capability_regs (entry.regs) from ghes_estatus_pool and queues the entry into aer_recover_ring.
In aer_recover_work_func(), items are popped from aer_recover_ring via kfifo_get(). If pci_get_domain_bus_and_slot() fails to find a matching pci_dev, the code previously executed 'continue', bypassing the call to ghes_estatus_pool_region_free(). As a result, the memory allocated for entry.regs from ghes_estatus_pool was leaked.
This is reachable whenever the device reported by firmware is not (or is no longer) present in the PCI device tree, e.g. after hot-removal or when firmware reports an error for a device the kernel never enumerated.
Refactor aer_recover_work_func() to ensure ghes_estatus_pool_region_free() is called unconditionally for every dequeued entry, releasing the pool memory even when pci_dev is missing.
--- drivers/pci/pcie/aer.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
drivers/pci/pcie/aer.c +12 -11
@@ -1005,13 +1005,12 @@ static void aer_recover_work_func(struct work_struct *work)while (kfifo_get (&aer_recover_ring, &entry)) { pdev =pci_get_domain_bus_and_slot (entry.domain, entry.bus, entry.devfn); -if (!pdev) { +if (!pdev)pr_err ("no pci_dev for %04x:%02x:%02x.%x\n" , entry.domain, entry.bus,PCI_SLOT (entry.devfn),PCI_FUNC (entry.devfn)); -continue ; - } -cper_print_aer (pdev, entry.severity, entry.regs); +else +cper_print_aer (pdev, entry.severity, entry.regs);/* * Memory for aer_capability_regs(entry.regs) is being allocated from the * ghes_estatus_pool to protect it from overwriting when multiple sections
@@ -1021,13 +1020,15 @@ static void aer_recover_work_func(struct work_struct *work)ghes_estatus_pool_region_free ((unsigned long )entry.regs,sizeof (struct aer_capability_regs )); -if (entry.severity ==AER_NONFATAL ) -pcie_do_recovery (pdev, pci_channel_io_normal, - aer_root_reset); -else if (entry.severity ==AER_FATAL ) -pcie_do_recovery (pdev, pci_channel_io_frozen, - aer_root_reset); -pci_dev_put (pdev); +if (pdev) { +if (entry.severity ==AER_NONFATAL ) +pcie_do_recovery (pdev, pci_channel_io_normal, + aer_root_reset); +else if (entry.severity ==AER_FATAL ) +pcie_do_recovery (pdev, pci_channel_io_frozen, + aer_root_reset); +pci_dev_put (pdev); + } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1868/3318 fbcon: Rebuild rotated font buffer on font change
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Yiqi <[email protected]>
[ Upstream commit e4b6b865d45d8dafb6c6f28c8a993a5b4431d25a ]
fbcon_rotate_font() caches a rotated copy of the console font in par->rotated.buf. The buffer is sized from the font's width, height and charcount, and is rebuilt in fbcon_init(), fbcon_switch() and fbcon_modechanged(), but not in fbcon_do_set_font().
When the font is changed through KDFONTOP, the new geometry is installed and vc_resize() redraws before the buffer is rebuilt. The rotated putcs/cursor ops then index the old buffer with the new cell size; KASAN reports a slab-out-of-bounds read in soft_cursor().
Rebuild the buffer for the visible console before the redraw, as the other callers do: select the console's blitting state with set_blitting_type() (which also uploads the new font's map on tile-blitting hardware), then rebuild. Background consoles keep their rebuild at fbcon_switch() time, as the buffer is shared per framebuffer and must not be updated for a console that is not being displayed.
To ensure a correct rollback when the rebuild or the following vc_resize() fails, save the rotated font state, clear it before rebuilding, and restore it in the error path of fbcon_do_set_font().
--- drivers/video/fbdev/core/fbcon.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/video/fbdev/core/fbcon.c +57 -0
@@ -2418,6 +2418,12 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,int resize, ret, old_userfont, old_width, old_height, old_charcount;u8 *old_data = vc->vc_font.data;unsigned short old_hi_font_mask = vc->vc_hi_font_mask; +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +u8 *saved_fontdata =NULL , *saved_fontbuffer =NULL ; +u32 saved_fd_size =0 ; +int saved_cur_rotate =0 ; +bool rotated_saved = false; +#endif resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); vc->vc_font.data = (void *)(p->fontdata = data);
@@ -2437,6 +2443,33 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!vc->vc_hi_font_mask && charcount ==512 )set_vc_hi_font (vc, true); +/* +* Select the console's blitting state and update the rotated font buffer +* to match the new font, so that the rendering below does not use a +* cache that was built for the old font. Clear the cached state so +* the rebuild allocates a fresh buffer; the old state is kept until +* the font change can no longer fail. +*/ +if (con_is_visible (vc)) { +set_blitting_type (vc, info); +if (par->rotate_font) { +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION + saved_fontdata = par->fontdata; + saved_fontbuffer = par->fontbuffer; + saved_fd_size = par->fd_size; + saved_cur_rotate = par->cur_rotate; + par->fontdata =NULL ; + par->fontbuffer =NULL ; + par->fd_size =0 ; + par->cur_rotate =0 ; + rotated_saved = true; +#endif + ret = par->rotate_font (info, vc); +if (ret) + goto err_out; + } + } +if (resize) {int cols, rows;
@@ -2453,11 +2486,28 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,update_screen (vc); } +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +if (rotated_saved) +kfree (saved_fontbuffer); +#endif if (old_userfont && (--REFCOUNT (old_data) ==0 ))kfree (old_data -FONT_EXTRA_WORDS *sizeof (int ));return 0 ; err_out: +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +/* +* Drop the buffer built for the new font and restore the saved +* state. +*/ +if (rotated_saved) { +kfree (par->fontbuffer); + par->fontdata = saved_fontdata; + par->fontbuffer = saved_fontbuffer; + par->fd_size = saved_fd_size; + par->cur_rotate = saved_cur_rotate; + } +#endif p->fontdata = old_data; vc->vc_font.data = old_data;
@@ -2477,6 +2527,13 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,else if (!old_hi_font_mask && vc->vc_hi_font_mask)set_vc_hi_font (vc, false); +/* +* Re-select the blitting type, which re-uploads the font map on +* tile-blitting hardware. +*/ +if (con_is_visible (vc)) +set_blitting_type (vc, info); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1869/3318 mm/memcontrol: fix stuck FLUSHING_CACHED_CHARGE bit on isolated cpus
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
[ Upstream commit d2f28a1a652e0a43f6f63de9b4e4d8d5f2716803 ]
When drain_all_stock() sets FLUSHING_CACHED_CHARGE before checking isolation, schedule_drain_work() can drop the work in a separate RCU critical section, and housekeeping_update()'s synchronize_rcu() can race that second check, leaving the flag set.
drain_local_stock() only clears the bit for work that ran, so the flag remains set and the stock is never drained again.
Have schedule_drain_work() return whether the work was queued, and clear FLUSHING_CACHED_CHARGE in drain_all_stock() when the remote CPU is isolated, so future drains can retry.
--- mm/memcontrol.c | 2 ++ 1 file changed, 2 insertions(+)
mm/memcontrol.c +2 -0
@@ -2396,6 +2396,8 @@ static void drain_all_stock(struct mem_cgroup *root_memcg)drain_local_stock (&stock->work); else if (!cpu_is_isolated(cpu)) schedule_work_on(cpu, &stock->work); + else + clear_bit(FLUSHING_CACHED_CHARGE, &stock->flags); } }migrate_enable ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1870/3318 btrfs: prevent deleting the wrong subvolume by ID
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: guolingxing <[email protected]>
[ Upstream commit 1960146913b31b288ed2cd607d103ee3b41681d4 ]
When deleting a subvolume by ID, btrfs_ioctl_snap_destroy() first resolves the requested ID to a name, then looks up that name again under the parent directory lock.
A concurrent rename can change which subvolume is associated with the name between these operations. Since the deletion path does not verify the ID of the resolved subvolume, it can delete a different subvolume while leaving the requested one intact.
This was reproduced by repeatedly exchanging the names of two subvolumes using renameat2(RENAME_EXCHANGE) while deleting one of them by ID. The wrong subvolume was deleted in 9 out of 14 independent tests.
Fix this by checking that the resolved subvolume ID matches the requested ID while holding the parent directory lock. Return -EAGAIN on a mismatch so that userspace can retry the operation instead of being told that the requested subvolume does not exist.
--- fs/btrfs/ioctl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/ioctl.c +11 -0
@@ -2535,6 +2535,17 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, inode =d_inode (dentry); dest =BTRFS_I (inode)->root; + +/* +* A concurrent rename may have changed which subvolume the name +* refers to. Verify that the resolved ID still matches the requested ID. +*/ +if (destroy_v2 && (vol_args2->flags &BTRFS_SUBVOL_SPEC_BY_ID ) && +btrfs_root_id (dest) != vol_args2->subvolid) { + err = -EAGAIN ; + goto out_dput; + } +if (!capable (CAP_SYS_ADMIN )) {/* * Regular user. Only allow this with a special mount
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1871/3318 ocfs2/heartbeat: serialize concurrent writes to a regions dev attribute
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eklavya Singh <[email protected]>
[ Upstream commit 0a8f258c0f012314c36b9e4818cdc0178c68f891 ]
o2hb_region_dev_store() checks reg->hr_bdev_file to see if the region is already started, but nothing stops two writers from doing that at the same time. configfs only serializes writes through the same open file, so two processes that each open the dev attribute can both get past the check:
A: hr_bdev_file is NULL, opens file A, sets hr_bdev_file = A
B: hr_bdev_file is NULL, opens file B, sets hr_bdev_file = B
A: start fails, fput(hr_bdev_file) drops B, sets it to NULL
B: start fails, fput(NULL)
Both calls also use the same hr_slots, hr_slot_data and hr_tmp_block, so the error paths can free the slot data twice.
syzbot hit the fput(NULL) with an unbound loop device, where every start fails with -EIO. With four threads doing the same thing on a KASAN kernel I get both crashes within a second:
BUG: KASAN: double-free in o2hb_unmap_slot_data+0x14d/0x2f0 BUG: kernel NULL pointer dereference, address: 0000000000000158
Add a mutex to the region and hold it in dev_store(), in the block_bytes, start_block and blocks stores, and in dev_show(), since they all look at hr_bdev_file. dev_store() cleans up with goto, so it takes the mutex in a small wrapper rather than with guard(). The mutex is dropped while dev_store() waits for the heartbeat to become steady, which takes seconds, so a read of dev doesn't stall behind a start. hr_bdev_file is already set at that point, so other writers still get -EINVAL, and the cleanup after the wait retakes the mutex.
With the patch the same test ran for 10 minutes with lockdep on and nothing was reported. So did a second one, with a working loop device, that interrupts starts during the wait while other threads read and write the attributes.
--- fs/ocfs2/cluster/heartbeat.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
fs/ocfs2/cluster/heartbeat.c +19 -2
@@ -268,6 +268,8 @@ struct o2hb_region {struct list_head hr_handler_list;/* Serializes timeout arming against failed-start and teardown. */ struct mutex hr_arming_mutex; +/* Serializes the dev, block_bytes, start_block and blocks attributes. */ +struct mutex hr_dev_mutex;bool hr_stopping;/* last hb status, 0 for success, other value for error. */
@@ -1657,6 +1659,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item,unsigned long block_bytes;unsigned int block_bits; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1686,6 +1689,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item,char *p = (char *)page;ssize_t ret; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1711,6 +1715,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,unsigned long tmp;char *p = (char *)page; +guard (mutex)(®->hr_dev_mutex);if (reg->hr_bdev)return -EINVAL ;
@@ -1728,10 +1733,12 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item,static ssize_t o2hb_region_dev_show (struct config_item *item,char *page) { +struct o2hb_region *reg =to_o2hb_region (item);unsigned int ret =0 ; -if (to_o2hb_region (item)->hr_bdev) - ret =sprintf (page,"%pg\n" ,to_o2hb_region (item)->hr_bdev); +guard (mutex)(®->hr_dev_mutex); +if (reg->hr_bdev) + ret =sprintf (page,"%pg\n" , reg->hr_bdev);return ret; }
@@ -1859,6 +1866,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item,ssize_t ret = -EINVAL ;int live_threshold; +mutex_lock (®->hr_dev_mutex); +if (reg->hr_bdev) goto out;
@@ -1959,9 +1968,15 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, reg->hr_task = hb_task;spin_unlock (&o2hb_live_lock); +/* +* Don't hold hr_dev_mutex across the wait, which can take seconds. +* hr_bdev is already set, so other writers still get -EINVAL. +*/ +mutex_unlock (®->hr_dev_mutex); ret =wait_event_interruptible (o2hb_steady_queue,atomic_read (®->hr_steady_iterations) ==0 || reg->hr_node_deleted); +mutex_lock (®->hr_dev_mutex);if (ret) {atomic_set (®->hr_steady_iterations,0 ); reg->hr_aborted_start =1 ;
@@ -2013,6 +2028,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out2:fdput (f); out: +mutex_unlock (®->hr_dev_mutex);return ret; }
@@ -2118,6 +2134,7 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *gINIT_LIST_HEAD (®->hr_all_item);mutex_init (®->hr_arming_mutex); +mutex_init (®->hr_dev_mutex); reg->hr_stopping = true;INIT_DELAYED_WORK (®->hr_write_timeout_work, o2hb_write_timeout);INIT_DELAYED_WORK (®->hr_nego_timeout_work, o2hb_nego_timeout);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1872/3318 ALSA: compress: fix buffer leak on failed SET_PARAMS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit fbc74ca9fbf7e0b8f6872ccac62f9f4a1f3b5e53 ]
When the driver has neither ops->copy nor a preallocated dma_buffer_p, snd_compr_allocate_buffer() kmallocs runtime->buffer. If ops->set_params() then rejects the parameters, SET_PARAMS fails, the stream stays in the OPEN state and keeps the buffer. The next SET_PARAMS allocates a new buffer and overwrites the pointer, so repeated SET_PARAMS calls with parameters that the driver rejects leak one buffer per call.
Release the framework-owned buffer when ops->set_params() fails on an OPEN stream, so that a failed SET_PARAMS leaves no buffer behind and the buffer is allocated only once per successful setup. Use the same ownership check as snd_compr_free().
--- sound/core/compress_offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/core/compress_offload.c +8 -1
@@ -607,8 +607,15 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) } retval = stream->ops->set_params (stream, params); -if (retval) +if (retval) { +/* the stream stays OPEN: drop the buffer of the rejected setup */ +if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN && + !stream->runtime->dma_buffer_p) { +kfree (stream->runtime->buffer); + stream->runtime->buffer =NULL ; + }return retval; + }if (stream->next_track)return retval;
Signature · 1 line
2.53.0