Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp169081lqh; Wed, 27 Mar 2024 19:51:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWFtUGX8lngPYVlhV5xhS5Wmv88r+ISkUTFaPoG8VZMEDR5wVXjK8qWb7XAP4GWdf2q0mRW1nKlTfTuslPZyy0YBL5k2RlTxDSKfFp+Lg== X-Google-Smtp-Source: AGHT+IGG5aNgjoXjtk0hSd5m3JZ1sw/yW8Q7Olb6H7naElF7c3vxtWEPCwFDilDTjzuLXDQ1rXFJ X-Received: by 2002:ae9:ee18:0:b0:789:e524:933b with SMTP id i24-20020ae9ee18000000b00789e524933bmr1287824qkg.31.1711594315641; Wed, 27 Mar 2024 19:51:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711594315; cv=pass; d=google.com; s=arc-20160816; b=QtU9nRHTBJVb2WeaZO9W+P726YhetGtWFNiRWR/xXzOEUScfRjVTCxQYhyRlraYeq1 rvXtWbk7p5BPGbWDQWdpycRB5dwsB6qs7pB4BhwkanlGV6jzIMdRC6Cx0bE7QY5wYBRy 5C2Coj8EsncPPAeOeIzL5FHGIJ+V9LroEjB0aF578t04SSybBL/X8gG+q9JiiydBAwNX 9a3Jp6hD78WidRmSdDpP+44LNyFlpzXMP7L7fyc5lsbjQWDlzhrb6MKJLsF5bYc4Cp+j /KCv4T+UmXKShfg1a+AGZPPm0mPezMb7mUuH+ZJvlKKwEzIRo39BHmf4kb7oyan2licA U3VQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=/4Ns6gaSo4Qq0IcoiML7N509X1eCvl6xcmeeJxScUyE=; fh=Wotajyn2O46WSIuf9+31k+nr0ZxFi4kA1FKhlW80YJo=; b=GMaFOq4xzNw7824S+aJxnD8P1YRpM46A03WYGqdTqoba7dHsd1lZxs+Sy18FM+9iFV +fwcEAXMx2X/LPTtwD5onv1NWmKKHERnGXQ6jiNoWI7+JboPCjrAruVbgUsr+ecak5yT aI4PTyBJ0HmAMV6A0yzFnHP8lIo3ur+TXqMuWqrTZp4RvoZiSm5/1d/raprK06PqR+Vs oOQrxvxD7qar17pacQ3WUwZP6QwQ8AbvJKsOneDGuV7uSI7SRS2w4yUhVdN4oPlEtjLP fDxm3X/yhLq4XwhuHELX6NcfuEEMLKv7JpZKPbcCX6Kbwn+PmF+0arGEUA6Xvw53fPfE 17Zw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ie+dgLo9; arc=pass (i=1 spf=pass spfdomain=flex--ackerleytng.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-122352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122352-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l19-20020a37f513000000b0078a4541695bsi530040qkk.503.2024.03.27.19.51.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 19:51:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ie+dgLo9; arc=pass (i=1 spf=pass spfdomain=flex--ackerleytng.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-122352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122352-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5B6E11C2B94E for ; Thu, 28 Mar 2024 02:51:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A39028DD8; Thu, 28 Mar 2024 02:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ie+dgLo9" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACF122555B for ; Thu, 28 Mar 2024 02:51:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711594283; cv=none; b=peNkhsjwy120DKugDR9yok9gu8/Ag4neaY0/WCM1xFS1h/YJ3n3+OfCgqh7gAdjvYzziEwYavIzRdVow/qteHa1QYTkB9d53Z7tsJyMnYXU8xSLBrujhlI0XhTe1RgUwgXoYGMN1sR43CWOslE99iA5eV7if7PXEmmjRyUlV6lo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711594283; c=relaxed/simple; bh=XIZ4f6D2msngrjo5E1BaCoNab5/MCdBimgyNp63AH30=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mx9MAWqjyvyht4zGC/CaMcDW7eD8K0VmCHpFimUAN/e1/1iV83EOhcHsxi75/Mcy229g258B6L7K7mTK+nf/8idMy/b82q+OAeN/D9vnSEIJ/y6fDgL2v8+EVwIYssgszfItdSuwtqz0wn5Cgucy7VuM6oSzPPguXSZ3RJ5AyLs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ie+dgLo9; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60cd62fa20fso10175307b3.3 for ; Wed, 27 Mar 2024 19:51:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711594280; x=1712199080; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/4Ns6gaSo4Qq0IcoiML7N509X1eCvl6xcmeeJxScUyE=; b=ie+dgLo9oTxbhMW+OplILQRF5YTpxG0aKIijgQ14PdvFen1mdDDzJ+G1GCnXWWImqm Rkq1zs0ZOmtLQr8VVFgINUAG7Un2zxCMZQs4+pJlswiQqteQQEpxVFkbsH1nZ92pdUz7 AnqNzFQso5IWFwmkcNdbnUuxmcAr2FcJmQAvhnosezGr9Menbr+axzuAf4vIkns/4rNM sDczgVwgNiu9i/IcwKfiUBq7bR5qpoft8P6hw74f//d+zVwzrTqDCCR3c9hVWvuNodQU HwtMXrJXjwSMkLWVmnb4xuYiolWlQIfbM4lhZ+wm0jtHKaOBDB8GGe4dpc7/ESEIpgvq wNsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711594280; x=1712199080; 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=/4Ns6gaSo4Qq0IcoiML7N509X1eCvl6xcmeeJxScUyE=; b=ufOmQq1QrKah5iamn/9JJEKJRSJLtFi6xu0JqkJddxT73Au+QHzjiKige3ycDpLxQ4 cooN7l8W/dM7Fs9eJgei9I99XST94AOgmc7ZzXKGPV0ipA8Rxk8hYtGveK6Nrqrs6V/X riVrMNcx6z0Fg+FCW4mB/cs8NXp358wMQmWjoSXPFK4f/AwFzsfIyAjslZ8zYIhU4mQd s0bdVxYNO9/ZB3cva91b8c5SAgf6pOuokSeaaQKl6KzazLRwDBUqRUR+nY9E/3APVjwc lYoUosLTmLaWl7lU5ihJ7mL1sC89UJOt8W+r+LLqggKHGb8rDUqPgZU0DWhNBatE/i2z S3dA== X-Forwarded-Encrypted: i=1; AJvYcCXldU5uyoj3OoJLAsDdsurDw3gKBXhxT2LG0OK8vcrHSvJX5cNp2NiAWP8yS/jmfHFZYKsDtMjSAvcO5fAXbiE9K3qisiMtAIXyZaBG X-Gm-Message-State: AOJu0YzbFUp3wNT7Jgb4YQk+yXrJeG6JoRQ5+aVJvLDYowpavwP2scI9 K217dMvhSzQIlV36MUURaJ1FxkUKrqTP8phPMwnSuZbSbgjsMJZ0v0/flOe/hzxAVxozuNcfRKK nKvf1SAT/TyrZ2NuMpcGvWw== X-Received: from ctop-sg.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:1223]) (user=ackerleytng job=sendgmr) by 2002:a81:6d43:0:b0:611:7358:6fa9 with SMTP id i64-20020a816d43000000b0061173586fa9mr298635ywc.0.1711594279878; Wed, 27 Mar 2024 19:51:19 -0700 (PDT) Date: Thu, 28 Mar 2024 02:51:15 +0000 In-Reply-To: <20240314232637.2538648-19-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240314232637.2538648-1-seanjc@google.com> <20240314232637.2538648-19-seanjc@google.com> Message-ID: Subject: Re: [PATCH 18/18] KVM: selftests: Drop @selector from segment helpers From: Ackerley Tng To: Sean Christopherson , Marc Zyngier , Oliver Upton , Paolo Bonzini , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sean Christopherson writes: > Drop the @selector from the kernel code, data, and TSS builders and > instead hardcode the respective selector in the helper. Accepting a > selector but not a base makes the selector useless, e.g. the data helper > can't create per-vCPU for FS or GS, and so loading GS with KERNEL_DS is > the only logical choice. > > And for code and TSS, there is no known reason to ever want multiple > segments, e.g. there are zero plans to support 32-bit kernel code (and > again, that would require more than just the selector). > > If KVM selftests ever do add support for per-vCPU segments, it'd arguably > be more readable to add a dedicated helper for building/setting the > per-vCPU segment, and move the common data segment code to an inner > helper. > > Lastly, hardcoding the selector reduces the probability of setting the > wrong selector in the vCPU versus what was created by the VM in the GDT. > > Signed-off-by: Sean Christopherson > --- > .../selftests/kvm/lib/x86_64/processor.c | 29 +++++++++---------- > 1 file changed, 14 insertions(+), 15 deletions(-) > > diff --git a/tools/testing/selftests/kvm/lib/x86_64/processor.c b/tools/testing/selftests/kvm/lib/x86_64/processor.c > index dab719ee7734..6abd50d6e59d 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/processor.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/processor.c > @@ -438,10 +438,10 @@ static void kvm_seg_fill_gdt_64bit(struct kvm_vm *vm, struct kvm_segment *segp) > desc->base3 = segp->base >> 32; > } > > -static void kvm_seg_set_kernel_code_64bit(uint16_t selector, struct kvm_segment *segp) > +static void kvm_seg_set_kernel_code_64bit(struct kvm_segment *segp) > { > memset(segp, 0, sizeof(*segp)); > - segp->selector = selector; > + segp->selector = KERNEL_CS; > segp->limit = 0xFFFFFFFFu; > segp->s = 0x1; /* kTypeCodeData */ > segp->type = 0x08 | 0x01 | 0x02; /* kFlagCode | kFlagCodeAccessed > @@ -452,10 +452,10 @@ static void kvm_seg_set_kernel_code_64bit(uint16_t selector, struct kvm_segment > segp->present = 1; > } > > -static void kvm_seg_set_kernel_data_64bit(uint16_t selector, struct kvm_segment *segp) > +static void kvm_seg_set_kernel_data_64bit(struct kvm_segment *segp) > { > memset(segp, 0, sizeof(*segp)); > - segp->selector = selector; > + segp->selector = KERNEL_DS; > segp->limit = 0xFFFFFFFFu; > segp->s = 0x1; /* kTypeCodeData */ > segp->type = 0x00 | 0x01 | 0x02; /* kFlagData | kFlagDataAccessed > @@ -480,13 +480,12 @@ vm_paddr_t addr_arch_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) > return vm_untag_gpa(vm, PTE_GET_PA(*pte)) | (gva & ~HUGEPAGE_MASK(level)); > } > > -static void kvm_seg_set_tss_64bit(vm_vaddr_t base, struct kvm_segment *segp, > - int selector) > +static void kvm_seg_set_tss_64bit(vm_vaddr_t base, struct kvm_segment *segp) > { > memset(segp, 0, sizeof(*segp)); > segp->base = base; > segp->limit = 0x67; > - segp->selector = selector; > + segp->selector = KERNEL_TSS; > segp->type = 0xb; > segp->present = 1; > } > @@ -510,11 +509,11 @@ static void vcpu_init_sregs(struct kvm_vm *vm, struct kvm_vcpu *vcpu) > sregs.efer |= (EFER_LME | EFER_LMA | EFER_NX); > > kvm_seg_set_unusable(&sregs.ldt); > - kvm_seg_set_kernel_code_64bit(KERNEL_CS, &sregs.cs); > - kvm_seg_set_kernel_data_64bit(KERNEL_DS, &sregs.ds); > - kvm_seg_set_kernel_data_64bit(KERNEL_DS, &sregs.es); > - kvm_seg_set_kernel_data_64bit(KERNEL_DS, &sregs.gs); > - kvm_seg_set_tss_64bit(vm->arch.tss, &sregs.tr, KERNEL_TSS); > + kvm_seg_set_kernel_code_64bit(&sregs.cs); > + kvm_seg_set_kernel_data_64bit(&sregs.ds); > + kvm_seg_set_kernel_data_64bit(&sregs.es); > + kvm_seg_set_kernel_data_64bit(&sregs.gs); > + kvm_seg_set_tss_64bit(vm->arch.tss, &sregs.tr); > > sregs.cr3 = vm->pgd; > vcpu_sregs_set(vcpu, &sregs); > @@ -588,13 +587,13 @@ static void vm_init_descriptor_tables(struct kvm_vm *vm) > > *(vm_vaddr_t *)addr_gva2hva(vm, (vm_vaddr_t)(&exception_handlers)) = vm->handlers; > > - kvm_seg_set_kernel_code_64bit(KERNEL_CS, &seg); > + kvm_seg_set_kernel_code_64bit(&seg); > kvm_seg_fill_gdt_64bit(vm, &seg); > > - kvm_seg_set_kernel_data_64bit(KERNEL_DS, &seg); > + kvm_seg_set_kernel_data_64bit(&seg); > kvm_seg_fill_gdt_64bit(vm, &seg); > > - kvm_seg_set_tss_64bit(vm->arch.tss, &seg, KERNEL_TSS); > + kvm_seg_set_tss_64bit(vm->arch.tss, &seg); > kvm_seg_fill_gdt_64bit(vm, &seg); > } > > -- > 2.44.0.291.gc1ea87d7ee-goog Reviewed-by: Ackerley Tng