Received: by 10.213.65.68 with SMTP id h4csp2133851imn; Sun, 8 Apr 2018 20:33:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/OMcV4puJC/ZhOX8Z6/qFU9j8rno61Bm4g68UoOyoYXIWJlrGPQxkCQ0HQLJNrhJGxkPKi X-Received: by 2002:a17:902:2c03:: with SMTP id m3-v6mr1426422plb.192.1523244813578; Sun, 08 Apr 2018 20:33:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523244813; cv=none; d=google.com; s=arc-20160816; b=IDjkUyAWXKnPa9AzxANG9sb9Tfohj1eC/HExVRHg05HkadPJrf4yQzbOYPXy+ZpgsF +h12O1m45i7UOGSeYlVWTrb5nWkPjRB/AITx0CD9c71PkhUV3D/hkhD1tv9ZqOsDzKwN DtxYbHM7/6lFw8cY5rLyNyeZVVt3vzB9N5B6iJqnqFQ+25s8yC9S6hFETUWhG6xse+I8 uE3cWWGL/9zEvsa2TN4kjgK2wIQKn48y1HhhmYHmMhUWNXKne0fQ7BZx3WnuGYBnHTWQ 4n1WBQ9NGYLD4hchDSZHOSZza2Pszl0A2adhTsHjtBCxnh2AZlY9XZBY0u338kPB8vet JuEA== 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=3+slkllpJOo2ijoNjx7nbUrPJWpiXWEuNdY+HIybJcM=; b=IzMoJm9iLsQuipFIk4QTf2oPn6zC0ddvXPnISA1ggsxjh1Ex0BTXHYfKWnWeFZ4atp WPrMe9vGTyzE0VbmcC8oSBIOGymknxbqsWougbhu08NFD2oRKFHFVfLiPsCWxY41q01N l74/uOx0ncUqQFZexdsjFT/veWkUog/tNwkA9VZZfh86/uNOj6X0MP3fox1jgic6Kw9p abqpQdZ71CBzA0g5lqYbWU0z5jE5PWcTgpiPa+fmdQ4QV+RGJS3Qi24p/kUrpHwN6cSz a3YJbGeX0SinK1NCw7o8a5uCdpCfw8pfgRG7CTro3v4OLzfGkKsojluPfJecRoAnv5uB SuLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BGmOBmMr; 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 d16-v6si13199390pll.214.2018.04.08.20.32.56; Sun, 08 Apr 2018 20:33:33 -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=BGmOBmMr; 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 S1752794AbeDID2Q (ORCPT + 99 others); Sun, 8 Apr 2018 23:28:16 -0400 Received: from mail-sn1nam02on0111.outbound.protection.outlook.com ([104.47.36.111]:52845 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754609AbeDIAWG (ORCPT ); Sun, 8 Apr 2018 20:22:06 -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=3+slkllpJOo2ijoNjx7nbUrPJWpiXWEuNdY+HIybJcM=; b=BGmOBmMrt1KxRZmQqtUWamQvH1GR5fRtzGnvznGQAszRIwhlyUY4qXgHalBGqOEFDZYbwDrnWXLfmU6pZDn8mAhhPdAiPkQ1+nOjDqbbeqE1VeavxFnWqAAGGRikbRwAIoG4DXc2r2YyvlyG1cr0n93ju8RVxXRVu61bdgKzQxQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0936.namprd21.prod.outlook.com (52.132.131.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:21:59 +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:21:59 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Paul Mackerras , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 009/161] KVM: PPC: Book3S HV: Enable migration of decrementer register Thread-Topic: [PATCH AUTOSEL for 4.14 009/161] KVM: PPC: Book3S HV: Enable migration of decrementer register Thread-Index: AQHTz5h48U+RubVx9kmQHLMUx5q5XQ== Date: Mon, 9 Apr 2018 00:19:48 +0000 Message-ID: <20180409001936.162706-9-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB0936;7:pBezmZQQKmt23cXmgrv0zcW5Pjf2y0YP8Ixhv9REXIJv/r3QXZpc3ZtlLp0+UMUz4AxKpkgmYze2/4KrziplefBrp2/C5jqUb4bL2lApswymBPE9AepOo+h2rygslifHTQ1IZguwFeqCTT2UZmR5Jp/NLHgf2nPCtLU/0h5XmE0ejxWXXp+tkNkpGUs2pXKMkI++iydLxve/J1hc+w1XwNkQgXN2RNVzQB1Xg/Ryn7XB5ba3ujjqwvBII07ROlta;20:OWjGTClGeS4bBN+Nt2d8R2XSpK8Y+X7AZlVNcBJT8F6VeJaPaiz+vt1kGjOrEjg9xOJIFBEwNoD4ND0SelpP6Q+2qocnVfATmh1lMj/8KsOBURrm13JyQSHG49Ap4ggELn+6Io0HVXDZ2XwIDM+AonGj498pmAEfTs9PWqKo5YE= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: e4c479c6-42c6-454d-6a5c-08d59dafe8a3 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0936; x-ms-traffictypediagnostic: DM5PR2101MB0936: 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)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0936;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0936; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(396003)(376002)(366004)(199004)(189003)(3660700001)(36756003)(2501003)(76176011)(10290500003)(2616005)(5250100002)(3280700002)(478600001)(1076002)(72206003)(6436002)(53936002)(486006)(476003)(4326008)(6486002)(107886003)(5660300001)(54906003)(110136005)(102836004)(2906002)(6116002)(3846002)(86612001)(81156014)(81166006)(6666003)(8936002)(305945005)(8676002)(2900100001)(6506007)(68736007)(14454004)(106356001)(105586002)(25786009)(6512007)(86362001)(99286004)(446003)(551984002)(59450400001)(10090500001)(11346002)(316002)(26005)(7736002)(66066001)(186003)(22452003)(97736004)(22906009)(32563001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0936;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: gobLc3kM7j+GSuJWQTtJwe09EoMPVV3t3qUCIrdYdu236lTjV6n+dF+Pm4GKi9YOLJy0Dmm3P2BDYtRrxPh06SB8AZ7yYySFSF0+Rhd1TSdpnSalgvx/SnXXFmbyaYGv3Hb/UOEkiDMEZs3kXQqqVboCdCrXFQVxjxOJGX+cPHzTGWbqyNcoVKpWcJQX0LgxbpgIqxNyY3vbGbLFQrYwGupNNkI/536m+osmHx+HkwIDy228ZPYtc5konfOxlt9tvXxvq4PEVrOYMCJiK1daMgIicwpk0LXTa2FWPw1ZWMSk5lpWXdsflr3o1crxeLxCLySeeKYwviaPH/qNIqu2soaPCyJymCGg5hk0JOOIo90aW7tdCnikjkctqf8h9PL42hGtINfwVjuviEuJjSUdQTWjSe2esVOJZgEziG6nkSI= 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: e4c479c6-42c6-454d-6a5c-08d59dafe8a3 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:19:48.2545 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0936 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 e63a35fafef0..0f9089416b4c 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1837,6 +1837,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 61d6049f4c1e..8aaec831053a 100644 --- a/arch/powerpc/include/uapi/asm/kvm.h +++ b/arch/powerpc/include/uapi/asm/kvm.h @@ -607,6 +607,8 @@ struct kvm_ppc_rmmu_info { #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 f48e3379a18a..e094dc90ff1b 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -1497,6 +1497,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; @@ -1724,6 +1728,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 2b02d51d14d8..ecb45361095b 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -758,7 +758,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