From patchwork Tue Jul 21 04:17:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11674927 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1C4713A4 for ; Tue, 21 Jul 2020 04:19:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 9AE6020792 for ; Tue, 21 Jul 2020 04:19:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iGa9D87z"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RPE+tWYj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AE6020792 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=O66HD9EkryBgrNtUlZ6gSTN5J28ksm+rn1frQT7F/Kw=; b=iGa9D87zSt/Btmet360SPp2/x YUMqb59xZhfTBq37Os6WZLDNojZsoKw/Z/I5OeTYf0U14Qcip7iHpAoMLATtNsIH0RGUqUGYGqy73 egliE9xHWkqp1ky8kSA+ko/okABBKd7Be4YquFhfAITiBb0ZLMf2qbfWhUPJcno6PJTXOV+k0B1It GsbZjPKISQOZEj360qOpIotbAD3xD3Jd4g2Chv30xYNw4KQ2uxSJtbDnuUHn+puoNZsg19rZJQEmX L94a1AllNhV5iY+WaxBYNRpiq9Z1QiTdSVK6hcqTYlyak9gCssW+abt4tO4HcPh7qXA9ZF+RmTQag f0NT6fWQA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjD-0005hf-Vx; Tue, 21 Jul 2020 04:18:08 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjB-0005hA-4z for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2020 04:18:06 +0000 Received: by mail-pg1-x544.google.com with SMTP id l63so11331166pge.12 for ; Mon, 20 Jul 2020 21:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=373R9ouGaabWkF9LOu0D0r/ZsTxSFcUlmLnh8I9bY0s=; b=RPE+tWYjEq8lfF5Lw3l/T2VT2gCqX3SDMnLPmA7+qFMTTKSKBzKX5ZJj+2qCHprw0X zhFj6A9WFsSrz9NAqY5J4gbiqPbJPY8qJRzhfwUq9lyt1Su+mlIO4+W8O1jXJzMvWNZQ 5uOA2k2a6QWmhZN5ysIsuMEd/nrlVlZBsmd/QDGma0t53aVuYeX9E2zytGNvy22clEmz swji83M0Z6BNIBEqYqvPmRvztC/wG/tcV8MVy6ra8iMBzCG8sUQBznsfD1Mynnvru0b0 TNO3NgvemhHKueBqbtH3AHZ82se4DMGdqjcTcO8iyQkGvM6awUyOp6uosnGYAdWDzPfp hQvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=373R9ouGaabWkF9LOu0D0r/ZsTxSFcUlmLnh8I9bY0s=; b=B+K3umyP9IdMKbI7kV0Fqv6iTCsF5WvRAWgh2TiEdvDKU6uJ428JELSOAwGrvJC8Nt KBamWoBn1DXsW088+aobD+MnCO6ks+lk+FhjVWOOnvdjfLjBk/Buc5gUBHyYUFt6G2as ZGVtGBQKPh9EKJoF/LGWPPmoxTaL9sdX8WLw8kIdBumJcjnMMYxdbe5kMLjkW427c2pt T3YnQOLtoLB9V088T/vKLAq4wSsoMkx6BmqhMA6Dsv8zJyhpXMjzLWfMfh7v32D9CBL+ aIXoenZGphhG5RtXgfWZJ66s88z5Skf9RT/frz6TaD9yWT0PD/IhVaXX4j+PpXlXh+9i X+JQ== X-Gm-Message-State: AOAM532CC2UpRYgfAF5TE15hMNMOSDurer8fd6K2S/SnxbeLScggDUAC eMZnNhfYFBlwHnqWNzhxanQ= X-Google-Smtp-Source: ABdhPJwVPnVtk5dh2Lh4fkPP3MVN8SquGMQEFuF8nfcQma0abf59oSZFhiCWcRp1e3eJXlBbB8zm0g== X-Received: by 2002:a63:417:: with SMTP id 23mr20032006pge.44.1595305083162; Mon, 20 Jul 2020 21:18:03 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id e28sm18467270pfm.177.2020.07.20.21.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 21:18:02 -0700 (PDT) From: Sergey Senozhatsky To: Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose Subject: [RFC][PATCH 1/4] arm64:kvm: define pv_state SMCCC HV calls Date: Tue, 21 Jul 2020 13:17:39 +0900 Message-Id: <20200721041742.197354-2-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> References: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_001806_127082_662AC5EB X-CRM114-Status: GOOD ( 10.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [sergey.senozhatsky[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: joelaf@google.com, linux-kernel@vger.kernel.org, Sergey Senozhatsky , suleiman@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org These will be used later on to configure and enable vCPU PV-state support, which is needed for vcpu_is_preempted(). Signed-off-by: Sergey Senozhatsky --- include/linux/arm-smccc.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 15c706fb0a37..cba054662692 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -99,6 +99,24 @@ ARM_SMCCC_OWNER_STANDARD_HYP, \ 0x21) +#define ARM_SMCCC_HV_PV_STATE_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD_HYP, \ + 0x22) + +#define ARM_SMCCC_HV_PV_STATE_INIT \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD_HYP, \ + 0x23) + +#define ARM_SMCCC_HV_PV_STATE_RELEASE \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD_HYP, \ + 0x24) + /* * Return codes defined in ARM DEN 0070A * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C From patchwork Tue Jul 21 04:17:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11674925 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8760D138C for ; Tue, 21 Jul 2020 04:19:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 60AE920792 for ; Tue, 21 Jul 2020 04:19:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dRket2HB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bqhSzg4Q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60AE920792 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2/5r7BO/8AtTjRlZ8g3X23B8kYQeY7Ql4WcdoZMqcXo=; b=dRket2HBRi2U7JwmAHKbiu7uN M4/3xvfQpSZuK2C+0S7VCr2EPu/jjMO2RjJAeALPWxEA+Y/Hzy2YQlNTzfmlfv7dK90e1wCd1q3rD bGvMq44HGGOpqs0ki4/jVi5/6oIGs8i4cTP0tcUtbwOhJ3DWV0oZTLhmXy3OFr3pXnmwqPs1dfJXu TU5wR4v2JNmBG1lYva9sNNdPPZgdOzcmGBRXCOO48MVIhYe/ki1uMApWXOI5auEjFunzE3XTMwoGH OZqkJTNzs+9ZtFw+H6a7AHhX+GxW8tHVQT56EJoHVHNbTARJkQxLZdbD7x7EIHi0Bp6BFRmtxqDH2 c67ib6V9A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjJ-0005iU-2p; Tue, 21 Jul 2020 04:18:13 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjF-0005hp-Q6 for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2020 04:18:11 +0000 Received: by mail-pg1-x544.google.com with SMTP id j19so11322599pgm.11 for ; Mon, 20 Jul 2020 21:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QhRkRM1m4qgsAo9eZ39otcpFvlPpO24W7mp8anbogBw=; b=bqhSzg4QOmAx8vDaoW+qgWApTlOrQm4qYUFBFPFk5eJ0mJKUnH+PBOy0rrPoVLuSvj G5nYm2pK68MYqj6x+TCFJB+f5jSKEM8VQr4aztw9FuTmTF+mMsEgmg/KgI32RN54P7bo Bn2WB2MaubV4PEisl9ole2vBWAje7/6zJzcOgvSaMXBVKWeu1m54/+zJ11AFQ9IAPZFj 91rrJTGVdFDuaP2F5FGqiWP3c4TtwHUsRxjZmJ/tHtgrRdyF4+P1bosWHGypJBEIDb/5 Aw3/2v/i3mKymhzPQPRC/tYJPoKK3JPXXYId/NMpEGilerA3j8tWesrhzp4XC8U4VWSl qwfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QhRkRM1m4qgsAo9eZ39otcpFvlPpO24W7mp8anbogBw=; b=aJmunoY7eX0GOfWyVgaILHVH0l85hUCAgv0cv1quFuEK5jsm/b0eG3C9HrcwecG4kI U+L0QvSf0UtMVJRXpEGA6no1gb4lhZQNClCTz4SABGI+GZs7MOAMveM4I+c9gCgMCdOQ 5iOUn7SG6zpNma1U4T9iUWFmCKugmAYfvSJ8T8pAa65aIMXGoSXv2gpgxr05IDXUCZl4 CsvricPSxIEtoe015O1f8pjSWS0SV6xEUF3G4N3gM+3v1y3qLbrUzqitODE25PrdemdG BVZ7+rPjzWB6oWm7XDZZHGgEV9faD8DGO0hfSZM+b19TljaK/jX9llr386cNbqTxT1VL 5JUg== X-Gm-Message-State: AOAM531UrKgbVN7R6NR1+8Jlcbx5TV4D6EPuuFcgduHz7X102BFDd0GV DdDMx5U1fS7l3UkNL5arecQ= X-Google-Smtp-Source: ABdhPJx4iEq46mQUJiDEqXIx/wrx7qJP7HCND86/POVGHX0/iSnb09hQdnlfUa/C3gaz4EjedXYGBg== X-Received: by 2002:aa7:9a84:: with SMTP id w4mr21905832pfi.13.1595305088045; Mon, 20 Jul 2020 21:18:08 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id e28sm18467270pfm.177.2020.07.20.21.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 21:18:07 -0700 (PDT) From: Sergey Senozhatsky To: Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose Subject: [RFC][PATCH 2/4] arm64: add guest pvstate support Date: Tue, 21 Jul 2020 13:17:40 +0900 Message-Id: <20200721041742.197354-3-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> References: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_001809_960522_0E148452 X-CRM114-Status: GOOD ( 21.88 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [sergey.senozhatsky[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: joelaf@google.com, linux-kernel@vger.kernel.org, Sergey Senozhatsky , suleiman@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org PV-state is a per-CPU struct, which, for the time being, holds boolean `preempted' vCPU state. During the startup, given that host supports PV-state, each guest vCPU sends a pointer to its per-CPU variable to the host as a payload with the SMCC HV call, so that host can update vCPU state when it puts or loads vCPU. This has impact on the guest's scheduler - it does check the state of the vCPU it wants to run a task on: [..] wake_up_process() try_to_wake_up() select_task_rq_fair() available_idle_cpu() vcpu_is_preempted() Some sched benchmarks data is available on the github page [0]. [0] https://github.com/sergey-senozhatsky/arm64-vcpu_is_preempted Signed-off-by: Sergey Senozhatsky --- arch/arm64/include/asm/paravirt.h | 15 ++++ arch/arm64/kernel/Makefile | 2 +- arch/arm64/kernel/paravirt-state.c | 117 +++++++++++++++++++++++++++++ arch/arm64/kernel/paravirt.c | 4 +- arch/arm64/kernel/time.c | 1 + 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/kernel/paravirt-state.c diff --git a/arch/arm64/include/asm/paravirt.h b/arch/arm64/include/asm/paravirt.h index cf3a0fd7c1a7..1bf164b2041b 100644 --- a/arch/arm64/include/asm/paravirt.h +++ b/arch/arm64/include/asm/paravirt.h @@ -7,12 +7,22 @@ struct static_key; extern struct static_key paravirt_steal_enabled; extern struct static_key paravirt_steal_rq_enabled; +struct pvstate_vcpu_info { + bool preempted; + u8 reserved[63]; +}; + +struct pv_state_ops { + bool (*vcpu_is_preempted)(int cpu); +}; + struct pv_time_ops { unsigned long long (*steal_clock)(int cpu); }; struct paravirt_patch_template { struct pv_time_ops time; + struct pv_state_ops state; }; extern struct paravirt_patch_template pv_ops; @@ -22,10 +32,15 @@ static inline u64 paravirt_steal_clock(int cpu) return pv_ops.time.steal_clock(cpu); } +bool native_vcpu_is_preempted(int cpu); +bool paravirt_vcpu_is_preempted(int cpu); + +int __init pv_state_init(void); int __init pv_time_init(void); #else +#define pv_state_init() do {} while (0) #define pv_time_init() do {} while (0) #endif // CONFIG_PARAVIRT diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 5fb9b728459b..18974d5e798d 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -48,7 +48,7 @@ obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o obj-$(CONFIG_ACPI) += acpi.o obj-$(CONFIG_ACPI_NUMA) += acpi_numa.o obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL) += acpi_parking_protocol.o -obj-$(CONFIG_PARAVIRT) += paravirt.o +obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt-state.o obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-$(CONFIG_HIBERNATION) += hibernate.o hibernate-asm.o obj-$(CONFIG_KEXEC_CORE) += machine_kexec.o relocate_kernel.o \ diff --git a/arch/arm64/kernel/paravirt-state.c b/arch/arm64/kernel/paravirt-state.c new file mode 100644 index 000000000000..4ae92a84c73d --- /dev/null +++ b/arch/arm64/kernel/paravirt-state.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#define pr_fmt(fmt) "arm-pvstate: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static DEFINE_PER_CPU(struct pvstate_vcpu_info, vcpus_states); + +bool native_vcpu_is_preempted(int cpu) +{ + return false; +} + +static bool pv_vcpu_is_preempted(int cpu) +{ + struct pvstate_vcpu_info *st; + + st = &per_cpu(vcpus_states, cpu); + return READ_ONCE(st->preempted); +} + +bool paravirt_vcpu_is_preempted(int cpu) +{ + return pv_ops.state.vcpu_is_preempted(cpu); +} + +static bool has_pvstate(void) +{ + struct arm_smccc_res res; + + /* To detect the presence of PV time support we require SMCCC 1.1+ */ + if (arm_smccc_1_1_get_conduit() == SMCCC_CONDUIT_NONE) + return false; + + arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_HV_PV_STATE_FEATURES, + &res); + + if (res.a0 != SMCCC_RET_SUCCESS) + return false; + return true; +} + +static int __pvstate_cpu_hook(unsigned int cpu, int event) +{ + struct arm_smccc_res res; + struct pvstate_vcpu_info *st; + + st = &per_cpu(vcpus_states, cpu); + arm_smccc_1_1_invoke(event, virt_to_phys(st), &res); + if (res.a0 != SMCCC_RET_SUCCESS) + return -EINVAL; + return 0; +} + +static int pvstate_cpu_init(unsigned int cpu) +{ + int ret = __pvstate_cpu_hook(cpu, ARM_SMCCC_HV_PV_STATE_INIT); + + if (ret) + pr_warn("Unable to ARM_SMCCC_HV_PV_STATE_INIT\n"); + return ret; +} + +static int pvstate_cpu_release(unsigned int cpu) +{ + int ret = __pvstate_cpu_hook(cpu, ARM_SMCCC_HV_PV_STATE_RELEASE); + + if (ret) + pr_warn("Unable to ARM_SMCCC_HV_PV_STATE_RELEASE\n"); + return ret; +} + +static int pvstate_register_hooks(void) +{ + int ret; + + ret = cpuhp_setup_state(CPUHP_AP_ARM_KVMPV_STARTING, + "hypervisor/arm/pvstate:starting", + pvstate_cpu_init, + pvstate_cpu_release); + if (ret < 0) + pr_warn("Failed to register CPU hooks\n"); + return ret; +} + +static int __pvstate_init(void) +{ + return pvstate_register_hooks(); +} + +int __init pv_state_init(void) +{ + int ret; + + if (!has_pvstate()) + return 0; + + ret = __pvstate_init(); + if (ret) + return ret; + + pv_ops.state.vcpu_is_preempted = pv_vcpu_is_preempted; + return 0; +} diff --git a/arch/arm64/kernel/paravirt.c b/arch/arm64/kernel/paravirt.c index 295d66490584..3fec7563ac27 100644 --- a/arch/arm64/kernel/paravirt.c +++ b/arch/arm64/kernel/paravirt.c @@ -26,7 +26,9 @@ struct static_key paravirt_steal_enabled; struct static_key paravirt_steal_rq_enabled; -struct paravirt_patch_template pv_ops; +struct paravirt_patch_template pv_ops = { + .state.vcpu_is_preempted = native_vcpu_is_preempted, +}; EXPORT_SYMBOL_GPL(pv_ops); struct pv_time_stolen_time_region { diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c index eebbc8d7123e..50c55792f72b 100644 --- a/arch/arm64/kernel/time.c +++ b/arch/arm64/kernel/time.c @@ -68,4 +68,5 @@ void __init time_init(void) lpj_fine = arch_timer_rate / HZ; pv_time_init(); + pv_state_init(); } From patchwork Tue Jul 21 04:17:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11674929 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03D46138C for ; Tue, 21 Jul 2020 04:19:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 D15D120792 for ; Tue, 21 Jul 2020 04:19:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ozaTe0aF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J9kQIHBi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D15D120792 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lmYZrdntv8YOohzH2Wf3ptwSPHlcNOtWKcqJgpQIa38=; b=ozaTe0aFVUGtoqAL59r1B6umR puG89i/zqniTkqMbs0MUgPu0HqTsljEbqcMrbi8R2g/hPJgbgkaZw8k+rBmJlj1gkTK12f2bXcPwN sVMgYbgIpn594hP3PwtUDxgdJlaZydRLueEVMEFJycfjEudkxT5ihcD9sTcZ8Gmr3zVxaWUboQSn+ ikjSrybea74TgacYEWzYUam7L85rqsMhpkpiZk+swoFJMDXhGK8v0soeUcX/ZvHEl5dlBTBWDDRG7 cJiNezK77imsqr09OTQaBltUG1wZZJeSaAXSkGvLk+zRYBxnJcIDc1kBDrjeheXP0zcWdNmEO79Mm Nogr1iB+A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjU-0005lg-20; Tue, 21 Jul 2020 04:18:24 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxjjP-0005kA-PZ for linux-arm-kernel@lists.infradead.org; Tue, 21 Jul 2020 04:18:20 +0000 Received: by mail-pl1-x641.google.com with SMTP id d1so9693361plr.8 for ; Mon, 20 Jul 2020 21:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HdrgiDjwQi3OXxJsXUESa6n0z/319Mf+JqDHrOU66kg=; b=J9kQIHBiFR2cBCKxhL+j9PrgKpcG/r5Le8QseNCHRtjcterReYFiv7fvrhsU4CcS00 C357fOgCmIvXpjMyqWX9aLfF2IYPjDTz8jRD7icKJCrsELYfzDqy43kknkJLNIDeIEVW WQCG4iOa5n/ZacA/O3S1XnrsihQqfsz9hzsfKmTpv8WWHlIZ3MqgeKtOUECEe2W2TyUN hR+l3HUDsNFWs/M9YBUrI1wOGIpfZNoN/q4qAat105HU7y8ZQtOPfbQh3BzkiZL+FMT7 1GUBAZ0smgg07lgbKHTGCvrEqFBXkEDa//CkdpMhiPkD+VvyDEpu2lk+MxRfXdlCeAGl 2qKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HdrgiDjwQi3OXxJsXUESa6n0z/319Mf+JqDHrOU66kg=; b=drt0vfRLZP690VnsoQ+qQFXL26CleSh5FOkagKUgZw18Wtxepshad3J0/qv2/hAQfY Ln8nRpAbSpmB+ouHZi4ORqP7OdA+L0xU/ZtHMhR2WixcFXLZ2eEecfTuYYZW43af305Q AStAgA0ZoNoZVD9x+dmomLx0ACF7HtuQX+g+AP4hQphymiLoOMHrLkmdKdwKRvWRItd3 2G1nQxnR4+sZSWwBkuKRsUaTwt6wgiUxi47I8HCEewW7lh3O5oy52A3dWXp7/i/gd1BK IMBsGGeWDs2l/fLMu7hDTvXw+uqbYcsHjN0iO0rNXQvdGWcJsJdl7/fAeduTB/hu4idR fncg== X-Gm-Message-State: AOAM53002YluEjy20xbK3F75+Y7EKC6pShAH/bzyRcR4hspgPhfYi4Mf eXIqROsNyZDcD+S6ejtQreM= X-Google-Smtp-Source: ABdhPJyue+HTI0GPUR9dn0lDQER+qd43Q72CqYIHp9HX2nZ8SZRkDJx0a1ktEgktFA2ACThVp6s6CA== X-Received: by 2002:a17:902:ed02:: with SMTP id b2mr21034822pld.121.1595305097820; Mon, 20 Jul 2020 21:18:17 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id e28sm18467270pfm.177.2020.07.20.21.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 21:18:17 -0700 (PDT) From: Sergey Senozhatsky To: Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose Subject: [RFC][PATCH 4/4] arm64: do not use dummy vcpu_is_preempted() anymore Date: Tue, 21 Jul 2020 13:17:42 +0900 Message-Id: <20200721041742.197354-5-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> References: <20200721041742.197354-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_001819_911762_8E6E51DE X-CRM114-Status: GOOD ( 10.40 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:641 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [sergey.senozhatsky[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: joelaf@google.com, linux-kernel@vger.kernel.org, Sergey Senozhatsky , suleiman@google.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org vcpu_is_preempted() now can represent the actual state of the VCPU, so the scheduler can make better decisions when it picks the idle CPU to enqueue a task on. I executed a whole bunch of scheduler tests [0]. One particular test that shows the importance of vcpu_is_preempted() is AIO stress-ng test: x Disabled vcpu_is_preempted() stress-ng: info: [100] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s stress-ng: info: [100] (secs) (secs) (secs) (real time) (usr+sys time) stress-ng: info: [100] aio 222927 10.01 0.89 27.61 22262.04 7822.00 stress-ng: info: [139] aio 217043 10.01 1.00 26.80 21685.46 7807.30 stress-ng: info: [178] aio 217261 10.01 1.08 26.79 21709.36 7795.51 + Enabled vcpu_is_preempted() stress-ng: info: [100] aio 432750 10.00 1.14 19.03 43264.33 21455.13 stress-ng: info: [139] aio 426771 10.01 1.09 18.67 42629.13 21597.72 stress-ng: info: [179] aio 533039 10.00 1.42 20.39 53281.70 24440.12 Signed-off-by: Sergey Senozhatsky --- arch/arm64/include/asm/spinlock.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/spinlock.h b/arch/arm64/include/asm/spinlock.h index 9083d6992603..6a390eeabe82 100644 --- a/arch/arm64/include/asm/spinlock.h +++ b/arch/arm64/include/asm/spinlock.h @@ -11,17 +11,20 @@ /* See include/linux/spinlock.h */ #define smp_mb__after_spinlock() smp_mb() -/* - * Changing this will break osq_lock() thanks to the call inside - * smp_cond_load_relaxed(). - * - * See: - * https://lore.kernel.org/lkml/20200110100612.GC2827@hirez.programming.kicks-ass.net - */ #define vcpu_is_preempted vcpu_is_preempted + +#ifdef CONFIG_PARAVIRT +extern bool paravirt_vcpu_is_preempted(int cpu); + +static inline bool vcpu_is_preempted(int cpu) +{ + return paravirt_vcpu_is_preempted(cpu); +} +#else static inline bool vcpu_is_preempted(int cpu) { return false; } +#endif /* CONFIG_PARAVIRT */ #endif /* __ASM_SPINLOCK_H */