Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp661812pxb; Wed, 15 Sep 2021 10:11:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/isuVbDM43Nl+KzauFUHex3LD5M/FxO06jlk9D2vpfuaCKU+o+ObfGFMYjLr80CM7bt9m X-Received: by 2002:a17:906:520b:: with SMTP id g11mr1108078ejm.502.1631725880585; Wed, 15 Sep 2021 10:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631725880; cv=none; d=google.com; s=arc-20160816; b=hrSMsun7zoalOa6OBs6wI/xntWqLWmOMVy4Otc/S6Mm79+cMt9Kq3DUEfVzkEzfyPi WdlDGO3Beg0FxivFDrXQ4XlapBknRP18DkQ1An7drZ19NjDSDJCyIzjdLM2UsYjOy+US hzT8RjzOB6t3QqJ4yS8DzLLTOs3otpncex38ELC3hvd2CxcxksRhjnfe9XsWOM8CFfxJ L5M6AAtndUmj0Q04BWbRK/3wuyEXp/1qdyErCKSXuiuEQ8YalLnYJtkDmlpHX9T9ZCcf ArZtRAO7kSOBg5NH5HRLD+mwU/TJhbfLBuEfN6eHbvOOQpcaJqJbT1GxZltPAswa7lAz JuMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=BHR7QtxSQA+/ZedfBKDXb+NcR7qgBuUccMd7nT8tD0k=; b=Z0HMV/7OSANWBDWyAEa/YQ+CcRCdiAtOt91Dln4OXEnUxfG0SxLBiMyTcFYMLKB/e6 jRWaR15JpfmYwtDkcv0BIbZhBXEj7lyBs/moFWwnlFffq1VK0gCStcMgS5oj3J2sFLjv 3k1jKLuIdBaPNUyr7UUpvlQem70aYZWxn4DysN5xIbFIqIvUy+lT483+0MQl1TN/Vun1 ZJrUnA/X8e1+PB4KiMpF41mu7V29Q6h4b4wfd3Nn4RYmcuT+vaZsuYwAaSCkxgRwwHwH zo3Yd+E+L1ll/sgZCKe+w3szVNMk7W9rb8lIZSpjlVG4NuwVJGm15l+zgorR8oNkeTq8 cvOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HFUlyDSV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f14si541609ejj.667.2021.09.15.10.10.55; Wed, 15 Sep 2021 10:11:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HFUlyDSV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbhIORKv (ORCPT + 99 others); Wed, 15 Sep 2021 13:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229465AbhIORKu (ORCPT ); Wed, 15 Sep 2021 13:10:50 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46313C061575 for ; Wed, 15 Sep 2021 10:09:31 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id i3-20020a056830210300b0051af5666070so4502463otc.4 for ; Wed, 15 Sep 2021 10:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=BHR7QtxSQA+/ZedfBKDXb+NcR7qgBuUccMd7nT8tD0k=; b=HFUlyDSV/PDxVFFF9p8abTMB/VRvN5zoI2a2tQfpl2PbcRHpXLQAdDBD/76ejENIN3 t9qQS+FXTdBL05lhAdXuyRGRCZ68NFianmrJSo67fEsMqPEYj/CSPivfSbrSfuocSyQk ykDT1pgkygwsN04Mho/nYvS2Lz0c6GSTSq+qoLoLTrsi3FWvUTC0laq0A4N08SoLw3GI VUsu2CYAb7OGs9KXNtMBk8FviT6fFT1bpI0+0ZPoF0WIlS3papnwN/GQAhA/Y96DpAre 5ylwNz1Q12t/g2XHtbjd0g1k4lOdG+nSbV0PoEJ9ewGx/rIKa9fbCPv/MY4dPfPuD6MU pF9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BHR7QtxSQA+/ZedfBKDXb+NcR7qgBuUccMd7nT8tD0k=; b=v6GIIjTlac0lohHoRW57zGk05/hipfLuvzTArErJUI3pnA5y6bSKa6ca6vOB7FFz7D RSv9B+sKObjczVTask6UXlSaBIUsDV+n8f8f6WC0LN2i+Rnpac58KQjkG+UBSwezP4w2 EJln0pbL62Oc3V+lQsNhFrMsLMJBqxjGkvBokuAcH7VhoqmlLftxGEGrbnZzDyOONIzg GYOFuMvrPC/jrHtcR9Uono3re3UBaG488a40maWJSk47xB9QhguiABEQXX7mXpSWNjfj NGEv+kcF3DQiua8GuGgTWvdoLo4uQaby3OCgqTB+2iUDDFCO+8jWADXg3DG7TgMJKwrS zGpg== X-Gm-Message-State: AOAM5332NYqTo/0ga2uH0B9iEcDw0gLvjgWx6m/p/N6ktuk5PO0gtZ1v 6QUXOJed2QCikSyoFsjl+yCoDCZyq98GSqm9Hp9+4w== X-Received: by 2002:a05:6830:349c:: with SMTP id c28mr925796otu.35.1631725770184; Wed, 15 Sep 2021 10:09:30 -0700 (PDT) MIME-Version: 1.0 References: <20210914164727.3007031-1-pgonda@google.com> <20210914164727.3007031-4-pgonda@google.com> In-Reply-To: <20210914164727.3007031-4-pgonda@google.com> From: Marc Orr Date: Wed, 15 Sep 2021 10:09:18 -0700 Message-ID: Subject: Re: [PATCH 3/4 V8] selftest: KVM: Add open sev dev helper To: Peter Gonda Cc: kvm list , Sean Christopherson , Paolo Bonzini , David Rientjes , "Dr . David Alan Gilbert" , Brijesh Singh , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 14, 2021 at 9:47 AM Peter Gonda wrote: > > Refactors out open path support from open_kvm_dev_path_or_exit() and > adds new helper for SEV device path. > > Signed-off-by: Peter Gonda > Suggested-by: Sean Christopherson > Cc: Marc Orr > Cc: Paolo Bonzini > Cc: Sean Christopherson > Cc: David Rientjes > Cc: Dr. David Alan Gilbert > Cc: Brijesh Singh > Cc: Vitaly Kuznetsov > Cc: Wanpeng Li > Cc: Jim Mattson > Cc: Joerg Roedel > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: kvm@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > --- > .../testing/selftests/kvm/include/kvm_util.h | 1 + > .../selftests/kvm/include/x86_64/svm_util.h | 2 ++ > tools/testing/selftests/kvm/lib/kvm_util.c | 24 +++++++++++-------- > tools/testing/selftests/kvm/lib/x86_64/svm.c | 13 ++++++++++ > 4 files changed, 30 insertions(+), 10 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h > index 010b59b13917..368e88305046 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util.h > +++ b/tools/testing/selftests/kvm/include/kvm_util.h > @@ -80,6 +80,7 @@ struct vm_guest_mode_params { > }; > extern const struct vm_guest_mode_params vm_guest_mode_params[]; > > +int open_path_or_exit(const char *path, int flags); > int open_kvm_dev_path_or_exit(void); > int kvm_check_cap(long cap); > int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap); > diff --git a/tools/testing/selftests/kvm/include/x86_64/svm_util.h b/tools/testing/selftests/kvm/include/x86_64/svm_util.h > index b7531c83b8ae..587fbe408b99 100644 > --- a/tools/testing/selftests/kvm/include/x86_64/svm_util.h > +++ b/tools/testing/selftests/kvm/include/x86_64/svm_util.h > @@ -46,4 +46,6 @@ static inline bool cpu_has_svm(void) > return ecx & CPUID_SVM; > } > > +int open_sev_dev_path_or_exit(void); > + > #endif /* SELFTEST_KVM_SVM_UTILS_H */ > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index 10a8ed691c66..06a6c04010fb 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -31,6 +31,19 @@ static void *align(void *x, size_t size) > return (void *) (((size_t) x + mask) & ~mask); > } > > +int open_path_or_exit(const char *path, int flags) > +{ > + int fd; > + > + fd = open(path, flags); > + if (fd < 0) { > + print_skip("%s not available (errno: %d)", path, errno); > + exit(KSFT_SKIP); > + } > + > + return fd; > +} > + > /* > * Open KVM_DEV_PATH if available, otherwise exit the entire program. > * > @@ -42,16 +55,7 @@ static void *align(void *x, size_t size) > */ > static int _open_kvm_dev_path_or_exit(int flags) > { > - int fd; > - > - fd = open(KVM_DEV_PATH, flags); > - if (fd < 0) { > - print_skip("%s not available, is KVM loaded? (errno: %d)", > - KVM_DEV_PATH, errno); > - exit(KSFT_SKIP); > - } > - > - return fd; > + return open_path_or_exit(KVM_DEV_PATH, flags); > } > > int open_kvm_dev_path_or_exit(void) > diff --git a/tools/testing/selftests/kvm/lib/x86_64/svm.c b/tools/testing/selftests/kvm/lib/x86_64/svm.c > index 2ac98d70d02b..14a8618efa9c 100644 > --- a/tools/testing/selftests/kvm/lib/x86_64/svm.c > +++ b/tools/testing/selftests/kvm/lib/x86_64/svm.c > @@ -13,6 +13,8 @@ > #include "processor.h" > #include "svm_util.h" > > +#define SEV_DEV_PATH "/dev/sev" > + > struct gpr64_regs guest_regs; > u64 rflags; > > @@ -160,3 +162,14 @@ void nested_svm_check_supported(void) > exit(KSFT_SKIP); > } > } > + > +/* > + * Open SEV_DEV_PATH if available, otherwise exit the entire program. > + * > + * Return: > + * The opened file descriptor of /dev/sev. > + */ > +int open_sev_dev_path_or_exit(void) > +{ > + return open_path_or_exit(SEV_DEV_PATH, 0); > +} > -- > 2.33.0.309.g3052b89438-goog > Reviewed-by: Marc Orr