From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04727C19F37 for ; Mon, 23 Aug 2021 15:00:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E38A061247 for ; Mon, 23 Aug 2021 15:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231690AbhHWPBH (ORCPT ); Mon, 23 Aug 2021 11:01:07 -0400 Received: from mail.efficios.com ([167.114.26.124]:33538 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbhHWPAw (ORCPT ); Mon, 23 Aug 2021 11:00:52 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A0106334FC6; Mon, 23 Aug 2021 11:00:08 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uKFyB1M3jATS; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 0D4FB334EEB; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 0D4FB334EEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1629730804; bh=EGJSeB1m+KUlEGsOyCQNymBM03QrlJxesVoB9WRZFHo=; h=Date:From:To:Message-ID:MIME-Version; b=ejPco84GHAXhi1/6wOVyAMnfI8z5LTzjRsTcS73jAocDos/Jg612nxN47CZzMjd1v j0dkSxvMADrUUQ6+2XaVpzg41uUfS876bws5Dc9KVmY3TbvU8bfG/GzZtSaU6MD/Br qd+yqE3E2LAVx+Wr4bAeKieW105tnSA1qBUEcAIFATAGYjySau7Gt6WOjEkKspWh2B avdwWhlGU945C6b8YvfAvk1ZdqEc2nt46fnvC2+SAOAbasQIeDIf96bdMWUzu3FQjr 7/tGcKmANl6xucIecfrF1a7WCI/NBUZnrQLCXvN+xT53buigZa/MX4DkWxF0/t6oL9 xwMUBg49cEiGg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3fgpCu_WLZGT; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id BD2C1335202; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Date: Mon, 23 Aug 2021 11:00:03 -0400 (EDT) From: Mathieu Desnoyers To: Sean Christopherson Cc: "Russell King, ARM Linux" , Catalin Marinas , Will Deacon , Guo Ren , Thomas Bogendoerfer , Michael Ellerman , Heiko Carstens , gor , Christian Borntraeger , rostedt , Ingo Molnar , Oleg Nesterov , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , paulmck , Boqun Feng , Paolo Bonzini , shuah , Benjamin Herrenschmidt , Paul Mackerras , linux-arm-kernel , linux-kernel , linux-csky , linux-mips , linuxppc-dev , linux-s390 , KVM list , linux-kselftest , Peter Foley , Shakeel Butt , Ben Gardon Message-ID: <733947967.21669.1629730803567.JavaMail.zimbra@efficios.com> In-Reply-To: <20210820225002.310652-2-seanjc@google.com> References: <20210820225002.310652-1-seanjc@google.com> <20210820225002.310652-2-seanjc@google.com> Subject: Re: [PATCH v2 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_4101 (ZimbraWebClient - FF90 (Linux)/8.8.15_GA_4059) Thread-Topic: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest Thread-Index: CeEx/cQL9qhzvrS0pzwTWVh97FgvJA== Precedence: bulk List-ID: X-Mailing-List: linux-csky@vger.kernel.org ----- On Aug 20, 2021, at 6:49 PM, Sean Christopherson seanjc@google.com wrote: > Invoke rseq's NOTIFY_RESUME handler when processing the flag prior to > transferring to a KVM guest, which is roughly equivalent to an exit to > userspace and processes many of the same pending actions. While the task > cannot be in an rseq critical section as the KVM path is reachable only > by via ioctl(KVM_RUN), the side effects that apply to rseq outside of a > critical section still apply, e.g. the current CPU needs to be updated if > the task is migrated. > > Clearing TIF_NOTIFY_RESUME without informing rseq can lead to segfaults > and other badness in userspace VMMs that use rseq in combination with KVM, > e.g. due to the CPU ID being stale after task migration. Acked-by: Mathieu Desnoyers > > Fixes: 72c3c0fe54a3 ("x86/kvm: Use generic xfer to guest work function") > Reported-by: Peter Foley > Bisected-by: Doug Evans > Cc: Shakeel Butt > Cc: Thomas Gleixner > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > kernel/entry/kvm.c | 4 +++- > kernel/rseq.c | 14 +++++++++++--- > 2 files changed, 14 insertions(+), 4 deletions(-) > > diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c > index 49972ee99aff..049fd06b4c3d 100644 > --- a/kernel/entry/kvm.c > +++ b/kernel/entry/kvm.c > @@ -19,8 +19,10 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, > unsigned long ti_work) > if (ti_work & _TIF_NEED_RESCHED) > schedule(); > > - if (ti_work & _TIF_NOTIFY_RESUME) > + if (ti_work & _TIF_NOTIFY_RESUME) { > tracehook_notify_resume(NULL); > + rseq_handle_notify_resume(NULL, NULL); > + } > > ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work); > if (ret) > diff --git a/kernel/rseq.c b/kernel/rseq.c > index 35f7bd0fced0..6d45ac3dae7f 100644 > --- a/kernel/rseq.c > +++ b/kernel/rseq.c > @@ -282,9 +282,17 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, > struct pt_regs *regs) > > if (unlikely(t->flags & PF_EXITING)) > return; > - ret = rseq_ip_fixup(regs); > - if (unlikely(ret < 0)) > - goto error; > + > + /* > + * regs is NULL if and only if the caller is in a syscall path. Skip > + * fixup and leave rseq_cs as is so that rseq_sycall() will detect and > + * kill a misbehaving userspace on debug kernels. > + */ > + if (regs) { > + ret = rseq_ip_fixup(regs); > + if (unlikely(ret < 0)) > + goto error; > + } > if (unlikely(rseq_update_cpu_id(t))) > goto error; > return; > -- > 2.33.0.rc2.250.ged5fa647cd-goog -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A85DC4320E for ; Mon, 23 Aug 2021 15:01:00 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B09426112F for ; Mon, 23 Aug 2021 15:00:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B09426112F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Gtb620KWrz2xvN for ; Tue, 24 Aug 2021 01:00:58 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=default header.b=ejPco84G; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=efficios.com (client-ip=167.114.26.124; helo=mail.efficios.com; envelope-from=compudj@efficios.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=default header.b=ejPco84G; dkim-atps=neutral Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Gtb5B0lqXz2xX3 for ; Tue, 24 Aug 2021 01:00:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A0106334FC6; Mon, 23 Aug 2021 11:00:08 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uKFyB1M3jATS; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 0D4FB334EEB; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 0D4FB334EEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1629730804; bh=EGJSeB1m+KUlEGsOyCQNymBM03QrlJxesVoB9WRZFHo=; h=Date:From:To:Message-ID:MIME-Version; b=ejPco84GHAXhi1/6wOVyAMnfI8z5LTzjRsTcS73jAocDos/Jg612nxN47CZzMjd1v j0dkSxvMADrUUQ6+2XaVpzg41uUfS876bws5Dc9KVmY3TbvU8bfG/GzZtSaU6MD/Br qd+yqE3E2LAVx+Wr4bAeKieW105tnSA1qBUEcAIFATAGYjySau7Gt6WOjEkKspWh2B avdwWhlGU945C6b8YvfAvk1ZdqEc2nt46fnvC2+SAOAbasQIeDIf96bdMWUzu3FQjr 7/tGcKmANl6xucIecfrF1a7WCI/NBUZnrQLCXvN+xT53buigZa/MX4DkWxF0/t6oL9 xwMUBg49cEiGg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3fgpCu_WLZGT; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id BD2C1335202; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Date: Mon, 23 Aug 2021 11:00:03 -0400 (EDT) From: Mathieu Desnoyers To: Sean Christopherson Message-ID: <733947967.21669.1629730803567.JavaMail.zimbra@efficios.com> In-Reply-To: <20210820225002.310652-2-seanjc@google.com> References: <20210820225002.310652-1-seanjc@google.com> <20210820225002.310652-2-seanjc@google.com> Subject: Re: [PATCH v2 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_4101 (ZimbraWebClient - FF90 (Linux)/8.8.15_GA_4059) Thread-Topic: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest Thread-Index: CeEx/cQL9qhzvrS0pzwTWVh97FgvJA== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: KVM list , Peter Zijlstra , linux-kernel , Will Deacon , Guo Ren , linux-kselftest , Ben Gardon , shuah , Paul Mackerras , linux-s390 , gor , "Russell King, ARM Linux" , linux-csky , Christian Borntraeger , Ingo Molnar , Catalin Marinas , linux-mips , Boqun Feng , paulmck , Heiko Carstens , rostedt , Shakeel Butt , Andy Lutomirski , Thomas Gleixner , Peter Foley , linux-arm-kernel , Thomas Bogendoerfer , Oleg Nesterov , Paolo Bonzini , linuxppc-dev Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" ----- On Aug 20, 2021, at 6:49 PM, Sean Christopherson seanjc@google.com wrote: > Invoke rseq's NOTIFY_RESUME handler when processing the flag prior to > transferring to a KVM guest, which is roughly equivalent to an exit to > userspace and processes many of the same pending actions. While the task > cannot be in an rseq critical section as the KVM path is reachable only > by via ioctl(KVM_RUN), the side effects that apply to rseq outside of a > critical section still apply, e.g. the current CPU needs to be updated if > the task is migrated. > > Clearing TIF_NOTIFY_RESUME without informing rseq can lead to segfaults > and other badness in userspace VMMs that use rseq in combination with KVM, > e.g. due to the CPU ID being stale after task migration. Acked-by: Mathieu Desnoyers > > Fixes: 72c3c0fe54a3 ("x86/kvm: Use generic xfer to guest work function") > Reported-by: Peter Foley > Bisected-by: Doug Evans > Cc: Shakeel Butt > Cc: Thomas Gleixner > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > kernel/entry/kvm.c | 4 +++- > kernel/rseq.c | 14 +++++++++++--- > 2 files changed, 14 insertions(+), 4 deletions(-) > > diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c > index 49972ee99aff..049fd06b4c3d 100644 > --- a/kernel/entry/kvm.c > +++ b/kernel/entry/kvm.c > @@ -19,8 +19,10 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, > unsigned long ti_work) > if (ti_work & _TIF_NEED_RESCHED) > schedule(); > > - if (ti_work & _TIF_NOTIFY_RESUME) > + if (ti_work & _TIF_NOTIFY_RESUME) { > tracehook_notify_resume(NULL); > + rseq_handle_notify_resume(NULL, NULL); > + } > > ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work); > if (ret) > diff --git a/kernel/rseq.c b/kernel/rseq.c > index 35f7bd0fced0..6d45ac3dae7f 100644 > --- a/kernel/rseq.c > +++ b/kernel/rseq.c > @@ -282,9 +282,17 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, > struct pt_regs *regs) > > if (unlikely(t->flags & PF_EXITING)) > return; > - ret = rseq_ip_fixup(regs); > - if (unlikely(ret < 0)) > - goto error; > + > + /* > + * regs is NULL if and only if the caller is in a syscall path. Skip > + * fixup and leave rseq_cs as is so that rseq_sycall() will detect and > + * kill a misbehaving userspace on debug kernels. > + */ > + if (regs) { > + ret = rseq_ip_fixup(regs); > + if (unlikely(ret < 0)) > + goto error; > + } > if (unlikely(rseq_update_cpu_id(t))) > goto error; > return; > -- > 2.33.0.rc2.250.ged5fa647cd-goog -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4374CC4338F for ; Mon, 23 Aug 2021 15:02:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A9F961242 for ; Mon, 23 Aug 2021 15:02:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0A9F961242 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Subject:References: In-Reply-To:Message-ID:Cc:To:From:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NfOSNIIMIY8pviwBkleyXZmK7e0lU14qTL1OBCsD+Ss=; b=mYjK051/BiyxgeUXW/rvVX7cZB hPOqzBTR64zzarSAWpaGShxIRGrPy1Sj/RepzQoNSs5wPSrjC7lleuuHwpssgvuJu5fvPtydO4oaI ZB7e20Z1fDzlhzV3pJ+1pYOsVRqBrIidUpgTnIMniBJbNJrQGR1vPii+3VF0zaOUtOIdC6MfaY2G1 mRNBTc3heW3QFcuwbq3XUGjJPD/Ky3ytf3HN7rR155GkGVw8V0MY59wTBJMiYmS1O5umW0Kv8fdEC xhEyK5YIxWOrx0GnLPh7wQQSvVaaEMR1D7B5pN4YFBTATASCftcRKk4SG3mpwclvsckFTAyeGM/dr yLze5kVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIBRE-00HLiR-Re; Mon, 23 Aug 2021 15:00:37 +0000 Received: from mail.efficios.com ([167.114.26.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mIBR8-00HLSO-4b for linux-arm-kernel@lists.infradead.org; Mon, 23 Aug 2021 15:00:35 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id A0106334FC6; Mon, 23 Aug 2021 11:00:08 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uKFyB1M3jATS; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 0D4FB334EEB; Mon, 23 Aug 2021 11:00:04 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 0D4FB334EEB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1629730804; bh=EGJSeB1m+KUlEGsOyCQNymBM03QrlJxesVoB9WRZFHo=; h=Date:From:To:Message-ID:MIME-Version; b=ejPco84GHAXhi1/6wOVyAMnfI8z5LTzjRsTcS73jAocDos/Jg612nxN47CZzMjd1v j0dkSxvMADrUUQ6+2XaVpzg41uUfS876bws5Dc9KVmY3TbvU8bfG/GzZtSaU6MD/Br qd+yqE3E2LAVx+Wr4bAeKieW105tnSA1qBUEcAIFATAGYjySau7Gt6WOjEkKspWh2B avdwWhlGU945C6b8YvfAvk1ZdqEc2nt46fnvC2+SAOAbasQIeDIf96bdMWUzu3FQjr 7/tGcKmANl6xucIecfrF1a7WCI/NBUZnrQLCXvN+xT53buigZa/MX4DkWxF0/t6oL9 xwMUBg49cEiGg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3fgpCu_WLZGT; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id BD2C1335202; Mon, 23 Aug 2021 11:00:03 -0400 (EDT) Date: Mon, 23 Aug 2021 11:00:03 -0400 (EDT) From: Mathieu Desnoyers To: Sean Christopherson Cc: "Russell King, ARM Linux" , Catalin Marinas , Will Deacon , Guo Ren , Thomas Bogendoerfer , Michael Ellerman , Heiko Carstens , gor , Christian Borntraeger , rostedt , Ingo Molnar , Oleg Nesterov , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , paulmck , Boqun Feng , Paolo Bonzini , shuah , Benjamin Herrenschmidt , Paul Mackerras , linux-arm-kernel , linux-kernel , linux-csky , linux-mips , linuxppc-dev , linux-s390 , KVM list , linux-kselftest , Peter Foley , Shakeel Butt , Ben Gardon Message-ID: <733947967.21669.1629730803567.JavaMail.zimbra@efficios.com> In-Reply-To: <20210820225002.310652-2-seanjc@google.com> References: <20210820225002.310652-1-seanjc@google.com> <20210820225002.310652-2-seanjc@google.com> Subject: Re: [PATCH v2 1/5] KVM: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest MIME-Version: 1.0 X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_4101 (ZimbraWebClient - FF90 (Linux)/8.8.15_GA_4059) Thread-Topic: rseq: Update rseq when processing NOTIFY_RESUME on xfer to KVM guest Thread-Index: CeEx/cQL9qhzvrS0pzwTWVh97FgvJA== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210823_080030_363775_7C2BD1C4 X-CRM114-Status: GOOD ( 23.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org ----- On Aug 20, 2021, at 6:49 PM, Sean Christopherson seanjc@google.com wrote: > Invoke rseq's NOTIFY_RESUME handler when processing the flag prior to > transferring to a KVM guest, which is roughly equivalent to an exit to > userspace and processes many of the same pending actions. While the task > cannot be in an rseq critical section as the KVM path is reachable only > by via ioctl(KVM_RUN), the side effects that apply to rseq outside of a > critical section still apply, e.g. the current CPU needs to be updated if > the task is migrated. > > Clearing TIF_NOTIFY_RESUME without informing rseq can lead to segfaults > and other badness in userspace VMMs that use rseq in combination with KVM, > e.g. due to the CPU ID being stale after task migration. Acked-by: Mathieu Desnoyers > > Fixes: 72c3c0fe54a3 ("x86/kvm: Use generic xfer to guest work function") > Reported-by: Peter Foley > Bisected-by: Doug Evans > Cc: Shakeel Butt > Cc: Thomas Gleixner > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > kernel/entry/kvm.c | 4 +++- > kernel/rseq.c | 14 +++++++++++--- > 2 files changed, 14 insertions(+), 4 deletions(-) > > diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c > index 49972ee99aff..049fd06b4c3d 100644 > --- a/kernel/entry/kvm.c > +++ b/kernel/entry/kvm.c > @@ -19,8 +19,10 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, > unsigned long ti_work) > if (ti_work & _TIF_NEED_RESCHED) > schedule(); > > - if (ti_work & _TIF_NOTIFY_RESUME) > + if (ti_work & _TIF_NOTIFY_RESUME) { > tracehook_notify_resume(NULL); > + rseq_handle_notify_resume(NULL, NULL); > + } > > ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work); > if (ret) > diff --git a/kernel/rseq.c b/kernel/rseq.c > index 35f7bd0fced0..6d45ac3dae7f 100644 > --- a/kernel/rseq.c > +++ b/kernel/rseq.c > @@ -282,9 +282,17 @@ void __rseq_handle_notify_resume(struct ksignal *ksig, > struct pt_regs *regs) > > if (unlikely(t->flags & PF_EXITING)) > return; > - ret = rseq_ip_fixup(regs); > - if (unlikely(ret < 0)) > - goto error; > + > + /* > + * regs is NULL if and only if the caller is in a syscall path. Skip > + * fixup and leave rseq_cs as is so that rseq_sycall() will detect and > + * kill a misbehaving userspace on debug kernels. > + */ > + if (regs) { > + ret = rseq_ip_fixup(regs); > + if (unlikely(ret < 0)) > + goto error; > + } > if (unlikely(rseq_update_cpu_id(t))) > goto error; > return; > -- > 2.33.0.rc2.250.ged5fa647cd-goog -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel