From patchwork Wed Apr 19 02:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13216281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A5FEC77B75 for ; Wed, 19 Apr 2023 02:19:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231613AbjDSCTK (ORCPT ); Tue, 18 Apr 2023 22:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231577AbjDSCTI (ORCPT ); Tue, 18 Apr 2023 22:19:08 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42DEF187 for ; Tue, 18 Apr 2023 19:19:07 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54fba72c1adso151083177b3.18 for ; Tue, 18 Apr 2023 19:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681870746; x=1684462746; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=z7zzcGDZPbSte4f8fT9vbCw5LuF4xstdxjEG9JI5LdU=; b=1BpmpgNYdsRKvRk6qrTEJbdcclnYFCXUZ1sKONbsw5Ac+UIEhNn+Cnjg4xjnCGB5JQ Shim51D/sV8i+svuoxMw06bFf0Ucel+aJs/jZJJQ1BNVWu7V4xKCnMR7ZBqzsal8nEcV kZiYnCBxW/ZfmJF0FbIPl2er+nfPek/CxhnGqU0yeGxTQkO0OY60TJ9f3whZk7pwzDPA rVKqlgZTUyLiVhks/K6jyM9QOfSJkfori6PQ0DzF2ye/sOHYLOlYUmsp0B2Nv5eywmkS EwDe+BL0VSwDvG3ugu5GwSLOR0/NsBzFakFVtuLsKy/yuAWsB+PVHPnR285JBPVa1X9+ hNhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681870746; x=1684462746; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=z7zzcGDZPbSte4f8fT9vbCw5LuF4xstdxjEG9JI5LdU=; b=ArqWMhw6uE2lyDEASdiieHWqnv33Hu80t1kS8DEb6WmbMKCJL69PbNhBGzEOskvA/3 14NX9PJ0sH4QpbYAutbJ9TK8e/QMkwZoCWBNZQMgkx9rT77vpcViiBn73FP+SJyBkfee 2bawhjdoVR2Ly0ywJZldtoGA9t3Lr6citxOlHxvPzrAz8zMhsAWO3gOnHlbmH+Vwazkd iXmwvE9Y1VwWbDym39dN9XQdXVWIov11z7Ki9cFpgSWkiGY60C0f2x0zBue/T3t0NbyI ekeSsZDIy0fakQlZ5AaDStMv4ncDaG2ZubEPbamzuCj5UWG3x2Sndlgor7pkeJxGgJ5d wFGQ== X-Gm-Message-State: AAQBX9cGUpm0pAsMTCqHT5fsxh6LHJjQfZOgDLrtrcHsF1v2ThmztGaD P7DKL/AsWiB0NMV91Siiv3aHRsrKBPg= X-Google-Smtp-Source: AKy350Z/I1GCXlm8WzCDIqkLOeoag4XllnSKJRp0ZAYYdDCimf2ANR08QBaZ+Z2bMGMmbTBDeu0l1oEfJ0E= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:d814:0:b0:b96:7676:db47 with SMTP id p20-20020a25d814000000b00b967676db47mr433801ybg.13.1681870746505; Tue, 18 Apr 2023 19:19:06 -0700 (PDT) Date: Tue, 18 Apr 2023 19:18:51 -0700 In-Reply-To: <20230419021852.2981107-1-reijiw@google.com> Mime-Version: 1.0 References: <20230419021852.2981107-1-reijiw@google.com> X-Mailer: git-send-email 2.40.0.396.gfff15efe05-goog Message-ID: <20230419021852.2981107-2-reijiw@google.com> Subject: [PATCH v1 1/2] KVM: arm64: Acquire mp_state_lock in kvm_arch_vcpu_ioctl_vcpu_init() From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon , Reiji Watanabe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org kvm_arch_vcpu_ioctl_vcpu_init() doesn't acquire mp_state_lock when setting the mp_state to KVM_MP_STATE_RUNNABLE. Fix the code to acquire the lock. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/arm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index fbafcbbcc463..388aa4f18f21 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1244,8 +1244,11 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, */ if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) kvm_arm_vcpu_power_off(vcpu); - else + else { + spin_lock(&vcpu->arch.mp_state_lock); WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); + spin_unlock(&vcpu->arch.mp_state_lock); + } return 0; } From patchwork Wed Apr 19 02:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reiji Watanabe X-Patchwork-Id: 13216282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99A6AC77B76 for ; Wed, 19 Apr 2023 02:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbjDSCTM (ORCPT ); Tue, 18 Apr 2023 22:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231588AbjDSCTL (ORCPT ); Tue, 18 Apr 2023 22:19:11 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B90BC7 for ; Tue, 18 Apr 2023 19:19:09 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54c17fb245dso335116907b3.21 for ; Tue, 18 Apr 2023 19:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681870748; x=1684462748; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xOVoOXEuKgQg2tBCLrjO+Ie6Feguqmtzji3r08inyQ8=; b=GBpDxzuZ8iJftmRFbQ4u416CLpAaocgcZ258FLuBJdT5LXUXVoFni09Eq8Jyypgsdi i3e3mWkR61bQcOBiE2Na5nyLZ9Vodg+T18Ab03ypVpChrLseDg7l+pl9A/nIiyCxU2oa rXUs/G8SdfeIcRJ9MrRo96XWQfkkPzlaaoYvG8YVrySHFFhSYSJlQNXpboOcNU7QnRi2 N23NYdPybyffUM3dTo4131YLhg/3VGFXDfAx0oFFH9pojA5Pwdv2A7+FS+yWFrvLJImB EZfnFhoF34L7GoYAEWgrIRv2pu3Dzo4nE9mWrei7GCzVdLnkXrcmMY5eeBzO40mvwy/g rw+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681870748; x=1684462748; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xOVoOXEuKgQg2tBCLrjO+Ie6Feguqmtzji3r08inyQ8=; b=WrAWDfvzVlCvIRxRNys3kpqFfRiOm+RpXoyhSUCAc8Dd9zXhDNr/g3dfw7yMJNuA0l dPmWS+IbQcGjYynyFbTj0UXEoEz8kDyKBDPS2MkjzV8Yxctvjsmru4u1lBBbDtpmpmZb pJhEA4T52NOitkRg/swHKSy3rESL+WI7dyZ8Ux5eezLTaUuhYUHM99/FMSlp3iacl5pp Ljb4K0HVlZ6PI+Uol+1hYBaujnfMsGN+WdGOn+qhX5pfg0vvWx7xZvkkAR4Pc5BspL5F f2u7rFVF6Kc5NphaI5D/p4CYlvSDU6i2B+6UmGOXr1UVyVQlCxpoZy32MSJo5KL8lJTF usAw== X-Gm-Message-State: AAQBX9cXGNe9HkByBGUTRSSM3Msu6p+bHPNbDdNAKw1nJ/LPhzFqX7JR Bg/wvGHSSa14G7cebSCvpDg1Wi2vG3A= X-Google-Smtp-Source: AKy350ZAJNC+m10rAkRY8MhHkLcGAFWbMx7c2WWQF2YMC1seAPFdQ+q3ICVHOmnhHJFjhA4DMarFTvB+Emo= X-Received: from reijiw-west4.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:aa1]) (user=reijiw job=sendgmr) by 2002:a25:d68c:0:b0:b92:25bf:a6ba with SMTP id n134-20020a25d68c000000b00b9225bfa6bamr7234069ybg.6.1681870748829; Tue, 18 Apr 2023 19:19:08 -0700 (PDT) Date: Tue, 18 Apr 2023 19:18:52 -0700 In-Reply-To: <20230419021852.2981107-1-reijiw@google.com> Mime-Version: 1.0 References: <20230419021852.2981107-1-reijiw@google.com> X-Mailer: git-send-email 2.40.0.396.gfff15efe05-goog Message-ID: <20230419021852.2981107-3-reijiw@google.com> Subject: [PATCH v1 2/2] KVM: arm64: Have kvm_psci_vcpu_on() use WRITE_ONCE() to update mp_state From: Reiji Watanabe To: Marc Zyngier , Oliver Upton , kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon , Reiji Watanabe Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org All accessors of kvm_vcpu_arch::mp_state should be {READ,WRITE}_ONCE(), since readers of the mp_state don't acquire the mp_state_lock. Nonetheless, kvm_psci_vcpu_on() updates the mp_state without using WRITE_ONCE(). So, fix the code to update the mp_state using WRITE_ONCE. Signed-off-by: Reiji Watanabe --- arch/arm64/kvm/psci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 5767e6baa61a..d046e82e3723 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -110,7 +110,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) */ smp_wmb(); - vcpu->arch.mp_state.mp_state = KVM_MP_STATE_RUNNABLE; + WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); kvm_vcpu_wake_up(vcpu); out_unlock: