Received: by 10.213.65.68 with SMTP id h4csp2111787imn; Sun, 8 Apr 2018 20:01:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx48KpUxBs7H4UGArg2kqLteaAWQX/XMhLQRBHK/oVZld264MwZtQShbOzv5kDvNkbfiFDI9w X-Received: by 10.101.81.11 with SMTP id f11mr8262304pgq.150.1523242874222; Sun, 08 Apr 2018 20:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523242874; cv=none; d=google.com; s=arc-20160816; b=e9q4z7h5FsyG68abw7OihwG86jjGEkRry2sTkpNsMw1FQJDCTp7/QJo/9jiFMgeMBf 18H/zamvnUNFd+NdDjUesm/JcUQk1PrT30gz1By+71t/Wr4xe5542+m8k7tG8ei/RvPj eVqxaLcisRCC1CB3+Tw4y9lkrmPm2Dp3nc+wv54FVpXMqRKmopNXzbrWVILFXyrnUH3N HVN/rGqfvCs7GIKOVCPcdBhf/3VgaKnGZM2q4Ijkhjq/hfZkS3O8EBsFACkq5dLWzQ42 PeexLSi7XCFEDxMH61f7+QCzAEDwXEUHTKn3L58UMqe8dtwng1cPwK29Qv58OFnHrhe7 U6RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=YDAn6pEDvmQsPnCIFsOc0jGqU6D983NmbF8nPcDjh2U=; b=jnCwu9M/jqEGH4qEfGRcLpffX8F6BhDj4KRW1Os7YEV+e+p+MsJmrQZA+138yX+rZ1 b5wOL0deMR/xGFs6QHfws4FbtcKUSvZUEPSKOMmYz92uS3kpemQv0NQU/mE7WwbwUScK YkwgFfHhIkOnwk1GyE4Z4HAZ87Z65RmBsAzPCYcFu0pk2eeyJJwTSmPJyDH8mbYOOatP YOJ2/ZTdvGbFGYpO/RcywCr/pIz0j3cGxBvzwj+lkUDpYPKxR0Li0oMARhKIi9E/6Yh3 JFJ0pT8PflSuMa9O2Rgwk/Cc/IcL4ldSkuT7vPhk7QANcNFH3Bi80zmTlD6Tu/LwjMnq lczA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=KARW+wb+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l185si10681163pgd.108.2018.04.08.20.00.36; Sun, 08 Apr 2018 20:01:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=KARW+wb+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753051AbeDIARF (ORCPT + 99 others); Sun, 8 Apr 2018 20:17:05 -0400 Received: from mail-co1nam03on0128.outbound.protection.outlook.com ([104.47.40.128]:49080 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752946AbeDIAQ6 (ORCPT ); Sun, 8 Apr 2018 20:16:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=YDAn6pEDvmQsPnCIFsOc0jGqU6D983NmbF8nPcDjh2U=; b=KARW+wb+swMQ25Mn8y46nmv1oaWCI7TRJh6n4B5Z7Uv/7RvX5ZpH8cZZI35Il46n5Zkje0Ckxjf5n6aA1DeFGnMeXVIS76RcEhvQN/IRJMbYOsPiNzic9JO0453BozaAxohLf/RXT2uLA7B3euqF0PlirB5/peurYrhoFPPYzzk= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1127.namprd21.prod.outlook.com (52.132.132.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:16:53 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:16:53 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Paul Mackerras , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 012/189] KVM: PPC: Book3S HV: Enable migration of decrementer register Thread-Topic: [PATCH AUTOSEL for 4.15 012/189] KVM: PPC: Book3S HV: Enable migration of decrementer register Thread-Index: AQHTz5gP+lCLDsvEzU6g1wIxqVmzlA== Date: Mon, 9 Apr 2018 00:16:53 +0000 Message-ID: <20180409001637.162453-12-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1127;7:9UmGr0loWxBq/jS7D1YddlAgQ9yHFC03OICk3Czvw1yPxCfaLxRi3ZaNExjcK3DSEnMC4/EExL4KkfDQGFm2z6XpCZkrATuoVVF0xb+M5Kk4cturh2NETjn2C23DlWyuaJMFkuR1SFTGx3VAg9aEwnXGq8AMGLuiKaFVHolnqS60dVrQuP9UMf/Ktv04FvDdFpDVzllpYTKCr83l++jXq7I22hVKTSmtg8O7RbfBzkJN9h+yYODiiyl9BXGDs4D4;20:c5EwJUSatCulLZzgGzW9JAEYqxpitbSmAusSHXy+UWBR3rUkVPbqzL9fBuMcr2T82U2VwXUmnsCSnhO7A4aLStCqFRWD1aMzpqcE7Hyy5RXEOgUlWshZjCoi03tvns25tFw7YbZK8CNTE2uUtfvX8PNvk+kkXsfb5xm0I98rkRk= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 05ee223b-30d3-42e3-096d-08d59daf32b1 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1127; x-ms-traffictypediagnostic: DM5PR2101MB1127: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1127;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1127; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(39860400002)(376002)(346002)(366004)(189003)(199004)(105586002)(186003)(66066001)(6486002)(54906003)(7736002)(26005)(86362001)(316002)(305945005)(110136005)(478600001)(3280700002)(86612001)(10290500003)(25786009)(5250100002)(2616005)(99286004)(22452003)(5660300001)(3660700001)(2900100001)(81166006)(3846002)(2906002)(106356001)(6506007)(59450400001)(107886003)(486006)(8676002)(81156014)(14454004)(10090500001)(68736007)(551984002)(4326008)(6116002)(1076002)(72206003)(102836004)(97736004)(11346002)(8936002)(476003)(2501003)(6436002)(6512007)(446003)(76176011)(36756003)(53936002)(22906009)(32563001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1127;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: XYR7YTOPBnc82gZkqGWUtK/eV5eESnbgVwZg24sQQffvEVlYi06TB1Mx5w9+2sjpNTZUxUa7ibsSJpOPR0cm9/rPECGceusL7mjw5AH40Sg6W5UPhVqKUgCfEilzfz9P+SmrMq6ixvPaJwhDzrhF6Fct5/+S/GJ6S0bRzVXQE9JCsb0pdvVMmY4t6grrKz0iQCsuczB6JP80CYkVW/rKKA7Yp6Bn4kw8TNCxn3liy++HItNGvX1mqWjxqIhgwDQNNFCG00q8J5kPVYjf8gj6mPo87fi4eQYzFlfz8mOPnLyaauWOxDtaH1qO/RWBliUB4k8oQwMjX+XJwZF1mXQ1MXMloyswE9bhW1rIpbIJvh5HHqAEngzZWh7Yerwt1ekfi1ptUZu7GvZ+6kUSwPQ//GcIDSWcQ0aYuW+rnRF03vk= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 05ee223b-30d3-42e3-096d-08d59daf32b1 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:16:53.6218 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paul Mackerras [ Upstream commit 5855564c8ab2d9cefca7b2933bd19818eb795e40 ] This adds a register identifier for use with the one_reg interface to allow the decrementer expiry time to be read and written by userspace. The decrementer expiry time is in guest timebase units and is equal to the sum of the decrementer and the guest timebase. (The expiry time is used rather than the decrementer value itself because the expiry time is not constantly changing, though the decrementer value is, while the guest vcpu is not running.) Without this, a guest vcpu migrated to a new host will see its decrementer set to some random value. On POWER8 and earlier, the decrementer is 32 bits wide and counts down at 512MHz, so the guest vcpu will potentially see no decrementer interrupts for up to about 4 seconds, which will lead to a stall. With POWER9, the decrementer is now 56 bits side, so the stall can be much longer (up to 2.23 years) and more noticeable. To help work around the problem in cases where userspace has not been updated to migrate the decrementer expiry time, we now set the default decrementer expiry at vcpu creation time to the current time rather than the maximum possible value. This should mean an immediate decrementer interrupt when a migrated vcpu starts running. In cases where the decrementer is 32 bits wide and more than 4 seconds elapse between the creation of the vcpu and when it first runs, the decrementer would have wrapped around to positive values and there may still be a stall - but this is no worse than the current situation. In the large-decrementer case, we are sure to get an immediate decrementer interrupt (assuming the time from vcpu creation to first run is less than 2.23 years) and we thus avoid a very long stall. Signed-off-by: Paul Mackerras Signed-off-by: Sasha Levin --- Documentation/virtual/kvm/api.txt | 1 + arch/powerpc/include/uapi/asm/kvm.h | 2 ++ arch/powerpc/kvm/book3s_hv.c | 8 ++++++++ arch/powerpc/kvm/powerpc.c | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/= api.txt index fc3ae951bc07..d225ec217ebb 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1841,6 +1841,7 @@ registers, find a list below: PPC | KVM_REG_PPC_DBSR | 32 PPC | KVM_REG_PPC_TIDR | 64 PPC | KVM_REG_PPC_PSSCR | 64 + PPC | KVM_REG_PPC_DEC_EXPIRY | 64 PPC | KVM_REG_PPC_TM_GPR0 | 64 ... PPC | KVM_REG_PPC_TM_GPR31 | 64 diff --git a/arch/powerpc/include/uapi/asm/kvm.h b/arch/powerpc/include/uap= i/asm/kvm.h index 637b7263cb86..833ed9a16adf 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -632,6 +632,8 @@ struct kvm_ppc_cpu_char { #define KVM_REG_PPC_TIDR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbc) #define KVM_REG_PPC_PSSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbd) =20 +#define KVM_REG_PPC_DEC_EXPIRY (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbe) + /* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */ diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 6c402f6c4940..deffe36d8a2b 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1504,6 +1504,10 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vc= pu, u64 id, case KVM_REG_PPC_ARCH_COMPAT: *val =3D get_reg_val(id, vcpu->arch.vcore->arch_compat); break; + case KVM_REG_PPC_DEC_EXPIRY: + *val =3D get_reg_val(id, vcpu->arch.dec_expires + + vcpu->arch.vcore->tb_offset); + break; default: r =3D -EINVAL; break; @@ -1731,6 +1735,10 @@ static int kvmppc_set_one_reg_hv(struct kvm_vcpu *vc= pu, u64 id, case KVM_REG_PPC_ARCH_COMPAT: r =3D kvmppc_set_arch_compat(vcpu, set_reg_val(id, *val)); break; + case KVM_REG_PPC_DEC_EXPIRY: + vcpu->arch.dec_expires =3D set_reg_val(id, *val) - + vcpu->arch.vcore->tb_offset; + break; default: r =3D -EINVAL; break; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 0a7c88786ec0..f3a7a2fc3d70 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -763,7 +763,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) =20 hrtimer_init(&vcpu->arch.dec_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); vcpu->arch.dec_timer.function =3D kvmppc_decrementer_wakeup; - vcpu->arch.dec_expires =3D ~(u64)0; + vcpu->arch.dec_expires =3D get_tb(); =20 #ifdef CONFIG_KVM_EXIT_TIMING mutex_init(&vcpu->arch.exit_timing_lock); --=20 2.15.1