5.6.19-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 155/161 mmc: sdio: Fix several potential memory leaks in mmc_sdio_init_card()
In reply to Greg Kroah-HartmanFrom: Ulf Hansson <[email protected]>
commit a94a59f43749b4f8cd81b8be87c95f9ef898d19d upstream.
Over the years, the code in mmc_sdio_init_card() has grown to become quite messy. Unfortunate this has also lead to that several paths are leaking memory in form of an allocated struct mmc_card, which includes additional data, such as initialized struct device for example.
Unfortunate, it's a too complex task find each offending commit. Therefore, this change fixes all memory leaks at once.
--- drivers/mmc/core/sdio.c | 58 ++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/mmc/core/sdio.c +27 -31
@@ -584,7 +584,7 @@ try_again:*/ err =mmc_send_io_op_cond (host, ocr, &rocr);if (err) - goto err; +return err;/* * For SPI, enable CRC as appropriate.
@@ -592,17 +592,15 @@ try_again:if (mmc_host_is_spi (host)) { err =mmc_spi_set_crc (host, use_spi_crc);if (err) - goto err; +return err; }/* * Allocate card structure. */ card =mmc_alloc_card (host,NULL ); -if (IS_ERR (card)) { - err =PTR_ERR (card); - goto err; - } +if (IS_ERR (card)) +return PTR_ERR (card);if ((rocr &R4_MEMORY_PRESENT ) &&mmc_sd_get_cid (host, ocr & rocr, card->raw_cid,NULL ) ==0 ) {
@@ -610,19 +608,15 @@ try_again:if (oldcard && (oldcard->type !=MMC_TYPE_SD_COMBO ||memcmp (card->raw_cid, oldcard->raw_cid,sizeof (card->raw_cid)) !=0 )) { -mmc_remove_card (card); -pr_debug ("%s: Perhaps the card was replaced\n" , -mmc_hostname (host)); -return -ENOENT ; + err = -ENOENT ; + goto mismatch; } }else { card->type =MMC_TYPE_SDIO ;if (oldcard && oldcard->type !=MMC_TYPE_SDIO ) { -mmc_remove_card (card); -pr_debug ("%s: Perhaps the card was replaced\n" , -mmc_hostname (host)); -return -ENOENT ; + err = -ENOENT ; + goto mismatch; } }
@@ -677,7 +671,7 @@ try_again:if (!oldcard && card->type ==MMC_TYPE_SD_COMBO ) { err =mmc_sd_get_csd (host, card);if (err) -return err; + goto remove;mmc_decode_cid (card); }
@@ -704,7 +698,12 @@ try_again:mmc_set_timing (card->host,MMC_TIMING_SD_HS ); } - goto finish; +if (oldcard) +mmc_remove_card (card); +else + host->card = card; + +return 0 ; }/*
@@ -730,16 +729,14 @@ try_again: goto remove;if (oldcard) { -int same = (card->cis.vendor == oldcard->cis.vendor && - card->cis.device == oldcard->cis.device); -mmc_remove_card (card); -if (!same) { -pr_debug ("%s: Perhaps the card was replaced\n" , -mmc_hostname (host)); -return -ENOENT ; +if (card->cis.vendor == oldcard->cis.vendor && + card->cis.device == oldcard->cis.device) { +mmc_remove_card (card); + card = oldcard; + }else { + err = -ENOENT ; + goto mismatch; } - - card = oldcard; } card->ocr = ocr_card;mmc_fixup_device (card, sdio_fixup_methods);
@@ -800,16 +797,15 @@ try_again: err = -EINVAL ; goto remove; } -finish: -if (!oldcard) - host->card = card; + + host->card = card;return 0 ; +mismatch: +pr_debug ("%s: Perhaps the card was replaced\n" ,mmc_hostname (host)); remove: -if (!oldcard) +if (oldcard != card)mmc_remove_card (card); - -err:return err; }
Greg Kroah-Hartman
maintainerPATCH 156/161 block/floppy: fix contended case in floppy_queue_rq()
In reply to Greg Kroah-HartmanFrom: Jiri Kosina <[email protected]>
commit 263c61581a38d0a5ad1f5f4a9143b27d68caeffd upstream.
Since the switch of floppy driver to blk-mq, the contended (fdc_busy) case in floppy_queue_rq() is not handled correctly.
In case we reach floppy_queue_rq() with fdc_busy set (i.e. with the floppy locked due to another request still being in-flight), we put the request on the list of requests and return BLK_STS_OK to the block core, without actually scheduling delayed work / doing further processing of the request. This means that processing of this request is postponed until another request comes and passess uncontended.
Which in some cases might actually never happen and we keep waiting indefinitely. The simple testcase is
for i in `seq 1 2000`; do echo -en $i '\r'; blkid --info /dev/fd0 2> /dev/null; done
run in quemu. That reliably causes blkid eventually indefinitely hanging in __floppy_read_block_0() waiting for completion, as the BIO callback never happens, and no further IO is ever submitted on the (non-existent) floppy device. This was observed reliably on qemu-emulated device.
Fix that by not queuing the request in the contended case, and return BLK_STS_RESOURCE instead, so that blk core handles the request rescheduling and let it pass properly non-contended later.
--- drivers/block/floppy.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/block/floppy.c +5 -5
@@ -2902,17 +2902,17 @@ static blk_status_t floppy_queue_rq(stru (unsigned long long) current_req->cmd_flags))return BLK_STS_IOERR ; -spin_lock_irq (&floppy_lock); -list_add_tail (&bd->rq->queuelist, &floppy_reqs); -spin_unlock_irq (&floppy_lock); -if (test_and_set_bit (0 , &fdc_busy)) {/* fdc busy, this new request will be treated when the current one is done */ is_alive (__func__,"old request running" ); -return BLK_STS_OK ; +return BLK_STS_RESOURCE ; } +spin_lock_irq (&floppy_lock); +list_add_tail (&bd->rq->queuelist, &floppy_reqs); +spin_unlock_irq (&floppy_lock); + command_status =FD_COMMAND_NONE ;__reschedule_timeout (MAXTIMEOUT ,"fd_request" );set_fdc (0 );
Greg Kroah-Hartman
maintainerPATCH 157/161 xen/pvcalls-back: test for errors when calling backend_connect()
In reply to Greg Kroah-HartmanFrom: Juergen Gross <[email protected]>
commit c8d70a29d6bbc956013f3401f92a4431a9385a3c upstream.
backend_connect() can fail, so switch the device to connected only if no error occurred.
--- drivers/xen/pvcalls-back.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/xen/pvcalls-back.c +2 -1
@@ -1087,7 +1087,8 @@ static void set_backend_state(struct xencase XenbusStateInitialised:switch (state) {case XenbusStateConnected: -backend_connect (dev); +if (backend_connect (dev)) +return ;xenbus_switch_state (dev, XenbusStateConnected);break ;case XenbusStateClosing:
Greg Kroah-Hartman
maintainerPATCH 158/161 platform/x86: sony-laptop: SNC calls should handle BUFFER types
In reply to Greg Kroah-HartmanFrom: Mattia Dongili <[email protected]>
commit 47828d22539f76c8c9dcf2a55f18ea3a8039d8ef upstream.
After commit 6d232b29cfce ("ACPICA: Dispatcher: always generate buffer objects for ASL create_field() operator") ACPICA creates buffers even when new fields are small enough to fit into an integer. Many SNC calls counted on the old behaviour.
Since sony-laptop already handles the INTEGER/BUFFER case in sony_nc_buffer_call, switch sony_nc_int_call to use its more generic function instead.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207491
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1830150
--- drivers/platform/x86/sony-laptop.c | 53 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-)
drivers/platform/x86/sony-laptop.c +23 -30
@@ -757,33 +757,6 @@ static union acpi_object *__call_snc_metreturn result; } -static int sony_nc_int_call (acpi_handle handle,char *name,int *value, -int *result) -{ -union acpi_object *object =NULL ; -if (value) { -u64 v = *value; - object =__call_snc_method (handle, name, &v); - }else - object =__call_snc_method (handle, name,NULL ); - -if (!object) -return -EINVAL ; - -if (object->type !=ACPI_TYPE_INTEGER ) { -pr_warn ("Invalid acpi_object: expected 0x%x got 0x%x\n" , -ACPI_TYPE_INTEGER , object->type); -kfree (object); -return -EINVAL ; - } - -if (result) - *result = object->integer.value; - -kfree (object); -return 0 ; -} -#define MIN (a, b) (a > b ? b : a)static int sony_nc_buffer_call (acpi_handle handle,char *name,u64 *value,void *buffer,size_t buflen)
@@ -795,17 +768,20 @@ static int sony_nc_buffer_call(acpi_handif (!object)return -EINVAL ; -if (object->type ==ACPI_TYPE_BUFFER ) { +if (!buffer) { +/* do nothing */ + }else if (object->type ==ACPI_TYPE_BUFFER ) { len =MIN (buflen, object->buffer.length); +memset (buffer,0 , buflen);memcpy (buffer, object->buffer.pointer, len); }else if (object->type ==ACPI_TYPE_INTEGER ) { len =MIN (buflen,sizeof (object->integer.value)); +memset (buffer,0 , buflen);memcpy (buffer, &object->integer.value, len); }else { -pr_warn ("Invalid acpi_object: expected 0x%x got 0x%x\n" , -ACPI_TYPE_BUFFER , object->type); +pr_warn ("Unexpected acpi_object: 0x%x\n" , object->type); ret = -EINVAL ; }
@@ -813,6 +789,23 @@ static int sony_nc_buffer_call(acpi_handreturn ret; } +static int sony_nc_int_call (acpi_handle handle,char *name,int *value,int + *result) +{ +int ret; + +if (value) { +u64 v = *value; + + ret =sony_nc_buffer_call (handle, name, &v, result, +sizeof (*result)); + }else { + ret =sony_nc_buffer_call (handle, name,NULL , result, +sizeof (*result)); + } +return ret; +} +struct sony_nc_handles {u16 cap[0x10 ];struct device_attribute devattr;
Greg Kroah-Hartman
maintainerPATCH 159/161 platform/x86: sony-laptop: Make resuming thermal profile safer
In reply to Greg Kroah-HartmanFrom: Mattia Dongili <[email protected]>
commit 476d60b1b4c8a2b14a53ef9b772058f35e604661 upstream.
The thermal handle object may fail initialization when the module is loaded in the first place. Avoid attempting to use it on resume then.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207491
--- drivers/platform/x86/sony-laptop.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/platform/x86/sony-laptop.c +6 -1
@@ -2288,7 +2288,12 @@ static void sony_nc_thermal_cleanup(stru#ifdef CONFIG_PM_SLEEP static void sony_nc_thermal_resume (void ) { -unsigned int status =sony_nc_thermal_mode_get (); +int status; + +if (!th_handle) +return ; + + status =sony_nc_thermal_mode_get ();if (status != th_handle->mode)sony_nc_thermal_mode_set (th_handle->mode);
Greg Kroah-Hartman
maintainerPATCH 160/161 KVM: arm64: Synchronize sysreg state on injecting an AArch32 exception
In reply to Greg Kroah-HartmanFrom: Marc Zyngier <[email protected]>
commit 0370964dd3ff7d3d406f292cb443a927952cbd05 upstream.
On a VHE system, the EL1 state is left in the CPU most of the time, and only syncronized back to memory when vcpu_put() is called (most of the time on preemption).
Which means that when injecting an exception, we'd better have a way to either:
(1) write directly to the EL1 sysregs
(2) synchronize the state back to memory, and do the changes there
For an AArch64, we already do (1), so we are safe. Unfortunately, doing the same thing for AArch32 would be pretty invasive. Instead, we can easily implement (2) by calling the put/load architectural backends, and keep preemption disabled. We can then reload the state back into EL1.
--- arch/arm/include/asm/kvm_host.h | 2 ++ arch/arm64/include/asm/kvm_host.h | 2 ++ virt/kvm/arm/aarch32.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+)
arch/arm/include/asm/kvm_host.h +2 -0
@@ -453,4 +453,6 @@ static inline bool kvm_arm_vcpu_is_final return true; } +#define kvm_arm_vcpu_loaded (vcpu) (false) +#endif /* __ARM_KVM_HOST_H__ */
arch/arm64/include/asm/kvm_host.h +2 -0
@@ -685,4 +685,6 @@ bool kvm_arm_vcpu_is_finalized(struct kv#define kvm_arm_vcpu_sve_finalized (vcpu) \ ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) +#define kvm_arm_vcpu_loaded (vcpu) ((vcpu)->arch.sysregs_loaded_on_cpu) +#endif /* __ARM64_KVM_HOST_H__ */
virt/kvm/arm/aarch32.c +28 -0
@@ -33,6 +33,26 @@ static const u8 return_offsets[8][2] = { [7] = { 4, 4 }, /* FIQ, unused */ }; +static bool pre_fault_synchronize (struct kvm_vcpu *vcpu) +{ +preempt_disable (); +if (kvm_arm_vcpu_loaded (vcpu)) { +kvm_arch_vcpu_put (vcpu); +return true; + } + +preempt_enable (); +return false; +} + +static void post_fault_synchronize (struct kvm_vcpu *vcpu,bool loaded) +{ +if (loaded) { +kvm_arch_vcpu_load (vcpu,smp_processor_id ()); +preempt_enable (); + } +} +/* * When an exception is taken, most CPSR fields are left unchanged in the * handler. However, some are explicitly overridden (e.g. M[4:0]).
@@ -155,7 +175,10 @@ static void prepare_fault32(struct kvm_vvoid kvm_inject_undef32 (struct kvm_vcpu *vcpu) { +bool loaded =pre_fault_synchronize (vcpu); +prepare_fault32 (vcpu,PSR_AA32_MODE_UND ,4 ); +post_fault_synchronize (vcpu, loaded); }/*
@@ -168,6 +191,9 @@ static void inject_abt32(struct kvm_vcpuu32 vect_offset;u32 *far, *fsr;bool is_lpae; +bool loaded; + + loaded =pre_fault_synchronize (vcpu);if (is_pabt) { vect_offset =12 ;
@@ -191,6 +217,8 @@ static void inject_abt32(struct kvm_vcpu/* no need to shuffle FS[4] into DFSR[10] as its 0 */ *fsr = DFSR_FSC_EXTABT_nLPAE; } + +post_fault_synchronize (vcpu, loaded); }void kvm_inject_dabt32 (struct kvm_vcpu *vcpu,unsigned long addr)
Greg Kroah-Hartman
maintainerPATCH 161/161 KVM: arm64: Save the hosts PtrAuth keys in non-preemptible context
In reply to Greg Kroah-HartmanFrom: Marc Zyngier <[email protected]>
commit ef3e40a7ea8dbe2abd0a345032cd7d5023b9684f upstream.
When using the PtrAuth feature in a guest, we need to save the host's keys before allowing the guest to program them. For that, we dump them in a per-CPU data structure (the so called host context).
But both call sites that do this are in preemptible context, which may end up in disaster should the vcpu thread get preempted before reentering the guest.
Instead, save the keys eagerly on each vcpu_load(). This has an increased overhead, but is at least safe.
--- arch/arm/include/asm/kvm_emulate.h | 3 ++- arch/arm64/include/asm/kvm_emulate.h | 6 ------ arch/arm64/kvm/handle_exit.c | 19 ++----------------- virt/kvm/arm/arm.c | 22 +++++++++++++++++++++- 4 files changed, 25 insertions(+), 25 deletions(-)
arch/arm/include/asm/kvm_emulate.h +2 -1
@@ -367,6 +367,7 @@ static inline unsigned long vcpu_data_ho } } -static inline void vcpu_ptrauth_setup_lazy (struct kvm_vcpu *vcpu) {} +static inline bool vcpu_has_ptrauth (struct kvm_vcpu *vcpu) {return false; } +static inline void vcpu_ptrauth_disable (struct kvm_vcpu *vcpu) { }#endif /* __ARM_KVM_EMULATE_H__ */
arch/arm64/include/asm/kvm_emulate.h +0 -6
@@ -111,12 +111,6 @@ static inline void vcpu_ptrauth_disable( vcpu->arch.hcr_el2 &= ~(HCR_API |HCR_APK ); } -static inline void vcpu_ptrauth_setup_lazy (struct kvm_vcpu *vcpu) -{ -if (vcpu_has_ptrauth (vcpu)) -vcpu_ptrauth_disable (vcpu); -} -static inline unsigned long vcpu_get_vsesr (struct kvm_vcpu *vcpu) {return vcpu->arch.vsesr_el2;
arch/arm64/kvm/handle_exit.c +2 -17
@@ -162,31 +162,16 @@ static int handle_sve(struct kvm_vcpu *vreturn 1 ; } -#define __ptrauth_save_key (regs, key) \ -({ \ - regs[key ## KEYLO_EL1] = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \ - regs[key ## KEYHI_EL1] = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \ -}) -/* * Handle the guest trying to use a ptrauth instruction, or trying to access a * ptrauth register. */ void kvm_arm_vcpu_ptrauth_trap (struct kvm_vcpu *vcpu) { -struct kvm_cpu_context *ctxt; - -if (vcpu_has_ptrauth (vcpu)) { +if (vcpu_has_ptrauth (vcpu))vcpu_ptrauth_enable (vcpu); - ctxt = vcpu->arch.host_cpu_context; -__ptrauth_save_key (ctxt->sys_regs,APIA ); -__ptrauth_save_key (ctxt->sys_regs,APIB ); -__ptrauth_save_key (ctxt->sys_regs,APDA ); -__ptrauth_save_key (ctxt->sys_regs,APDB ); -__ptrauth_save_key (ctxt->sys_regs,APGA ); - }else { +else kvm_inject_undefined (vcpu); - } }/*
virt/kvm/arm/arm.c +21 -1
@@ -332,6 +332,16 @@ void kvm_arch_vcpu_unblocking(struct kvmpreempt_enable (); } +#ifdef CONFIG_ARM64 +#define __ptrauth_save_key (regs, key) \ +({ \ + regs[key ## KEYLO_EL1] = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \ + regs[key ## KEYHI_EL1] = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \ +}) +#else +#define __ptrauth_save_key (regs, key) do { } while (0) +#endif +void kvm_arch_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {int *last_ran;
@@ -365,7 +375,17 @@ void kvm_arch_vcpu_load(struct kvm_vcpuelse vcpu_set_wfx_traps (vcpu); -vcpu_ptrauth_setup_lazy (vcpu); +if (vcpu_has_ptrauth (vcpu)) { +struct kvm_cpu_context __maybe_unused *ctxt = vcpu->arch.host_cpu_context; + +__ptrauth_save_key (ctxt->sys_regs,APIA ); +__ptrauth_save_key (ctxt->sys_regs,APIB ); +__ptrauth_save_key (ctxt->sys_regs,APDA ); +__ptrauth_save_key (ctxt->sys_regs,APDB ); +__ptrauth_save_key (ctxt->sys_regs,APGA ); + +vcpu_ptrauth_disable (vcpu); + } }void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu)