Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp993354iob; Fri, 13 May 2022 18:55:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKr36QXsh2GrjpkbCcBnUWG1LflYrH78rS7YlyauU1mzbf9HLi5mhZ7Yfz2s8JPywdu7HZ X-Received: by 2002:a05:6000:2a2:b0:20c:999d:bdec with SMTP id l2-20020a05600002a200b0020c999dbdecmr6142290wry.36.1652493341233; Fri, 13 May 2022 18:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493341; cv=none; d=google.com; s=arc-20160816; b=h+Lnr/xGnaSu/v6cZh8TWxAOGJ44d77XBYvb32TYlF3hAbymT0U4nGqQnj0TVbL5CI fzAor6d352Ry4rhy8x/43SURjZA00ul2KoiYDpv+RAWBxr7WB7ubJVHr8T+NO7DxSDTQ xxOSqjM5oE8AeXAgoGTztNagwA6EwHdKBOaLETyWyhbz24q+wqiiufGGYynaWYHCM6LW BXtkjLEI0Y9TI+4lyNvhAwCWBgK5wkNvuYgc/vNtyEJUzQGrguTa0qWgR+GVqQzWoJQ8 cml7iZnH8zHAEiuu6ftHN6GpYbOqKtIobiEwZ8ItJTqrbJY2Sla6LC+i+TIH22JhT7U3 MKkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=BL3CJGsqY/cqdqqI7zN3z8l2hVpezWWDtzBjCtMeqUg=; b=vvJhu8ulYJ1CXaHOGrTxV6Ks3Pga6nGaBpE/IFavFU/yTZjF4nAVzuYkXk+BskYLPC LDnh3Vev15FI4qjkC/CPAz6z3Kz5dO8Zbdb4+Jof2j5PICzAC6xDU3TqngLj3TGSphe6 HQ5/cc7YNZlKPrxg3Y0+2zoi8+Pt8qE/81yZrAFpjCZ0EMlXceR0A2/ueno3/NiIvX+p T4eJde+sq0MoyPfgjmJZ0LgfpdziuNhYXvXyWxBS1fVCjd9KJwp4+4QsK8eVTGLT1Il+ /g9ysmOz7nhcg8YzzF7nzxrH7h5EGGmAOqqzwUzuJoQR97rCyF0cJ6yQJeVAhVZ2sese wQhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OXF1EdD8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c23-20020a05600c0ad700b003948e966d45si5880446wmr.171.2022.05.13.18.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:55:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OXF1EdD8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 019E3B4B1; Fri, 13 May 2022 17:18:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350016AbiELJb2 (ORCPT + 99 others); Thu, 12 May 2022 05:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346306AbiELJb1 (ORCPT ); Thu, 12 May 2022 05:31:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F59C612B5 for ; Thu, 12 May 2022 02:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652347884; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BL3CJGsqY/cqdqqI7zN3z8l2hVpezWWDtzBjCtMeqUg=; b=OXF1EdD8jFeB+hmkUpriJ/6Cws4uCCun+mg6TyM1izR2NWzZY/Tp+so0IdbCIdDYfsGML5 Rtl5tq8T8Vo/StlpfxynWddM6JoXBWKrIPrLnpy6vRH9FVYsfPtKCZzgcAXFzKnwuQVBnq pYl13KVvT/UmIULbllxQiY0OZF2yjuk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-82-ZgWfqGL5NZaX6eqPlHUbKw-1; Thu, 12 May 2022 05:31:22 -0400 X-MC-Unique: ZgWfqGL5NZaX6eqPlHUbKw-1 Received: by mail-wm1-f69.google.com with SMTP id o24-20020a05600c379800b003943412e81dso1443286wmr.6 for ; Thu, 12 May 2022 02:31:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=BL3CJGsqY/cqdqqI7zN3z8l2hVpezWWDtzBjCtMeqUg=; b=GFYhMmw50/vamzmKX/2I99PnR6usRG7S9dQ5qr8dqC9eOI4+pEOrEovSLuk7NIuXv3 HoOP5l6bhN6Wj814xyj+4OkV53IGX0m+MA3yzMOi3a/+flzPxiMYhL4TkJyVU5s+QpAF oFvsyCY9cm8kpNQ1lslC8OJ/+VPFx+BXLQPhA/yNqWqFS5/IaK5ymyI9cekEPRGJp/MN Ekn7jsQEZThMSb5gn/IbEk5f4BQH+hg9Z7hDb25a9LytYXEekEsCPofYeBkUF+lmj40F GrYwaEGolMKWZQxK5Y3JF3f3Mp+xIKfFLtQLYwrcIYsHGwRWhDKEBTjHGeEqE+YnQMPV 7THA== X-Gm-Message-State: AOAM533/ktiGOZC63JPlkqu7Nk8jeJseH8m9pf3rbnJcwXKOLh6yNwit 9Ke3PKZ4EXb+j79Vhaus9dF/gBr5ZZItpNbzWPB9jv2ESayci+J7HPI1I7jNX894mK0al8ID6Rd rxHGFsSYxkUk0F9TkL4VtnEX6 X-Received: by 2002:adf:fc42:0:b0:20a:c45d:3767 with SMTP id e2-20020adffc42000000b0020ac45d3767mr26462162wrs.486.1652347880721; Thu, 12 May 2022 02:31:20 -0700 (PDT) X-Received: by 2002:adf:fc42:0:b0:20a:c45d:3767 with SMTP id e2-20020adffc42000000b0020ac45d3767mr26462123wrs.486.1652347880418; Thu, 12 May 2022 02:31:20 -0700 (PDT) Received: from ?IPV6:2003:cb:c701:d200:ee5d:1275:f171:136d? (p200300cbc701d200ee5d1275f171136d.dip0.t-ipconnect.de. [2003:cb:c701:d200:ee5d:1275:f171:136d]) by smtp.gmail.com with ESMTPSA id z14-20020a1c4c0e000000b003942a244ecfsm2143561wmf.20.2022.05.12.02.31.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 02:31:19 -0700 (PDT) Message-ID: <76fd0c11-5b9b-0032-183b-54db650f13b1@redhat.com> Date: Thu, 12 May 2022 11:31:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH v9 3/3] s390x: KVM: resetting the Topology-Change-Report Content-Language: en-US To: Pierre Morel , kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, borntraeger@de.ibm.com, frankja@linux.ibm.com, cohuck@redhat.com, thuth@redhat.com, imbrenda@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, wintera@linux.ibm.com, seiden@linux.ibm.com, nrb@linux.ibm.com References: <20220506092403.47406-1-pmorel@linux.ibm.com> <20220506092403.47406-4-pmorel@linux.ibm.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220506092403.47406-4-pmorel@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06.05.22 11:24, Pierre Morel wrote: > During a subsystem reset the Topology-Change-Report is cleared. > Let's give userland the possibility to clear the MTCR in the case > of a subsystem reset. > > To migrate the MTCR, let's give userland the possibility to > query the MTCR state. > > Signed-off-by: Pierre Morel > --- > arch/s390/include/uapi/asm/kvm.h | 5 ++ > arch/s390/kvm/kvm-s390.c | 79 ++++++++++++++++++++++++++++++++ > 2 files changed, 84 insertions(+) > > diff --git a/arch/s390/include/uapi/asm/kvm.h b/arch/s390/include/uapi/asm/kvm.h > index 7a6b14874d65..abdcf4069343 100644 > --- a/arch/s390/include/uapi/asm/kvm.h > +++ b/arch/s390/include/uapi/asm/kvm.h > @@ -74,6 +74,7 @@ struct kvm_s390_io_adapter_req { > #define KVM_S390_VM_CRYPTO 2 > #define KVM_S390_VM_CPU_MODEL 3 > #define KVM_S390_VM_MIGRATION 4 > +#define KVM_S390_VM_CPU_TOPOLOGY 5 > > /* kvm attributes for mem_ctrl */ > #define KVM_S390_VM_MEM_ENABLE_CMMA 0 > @@ -171,6 +172,10 @@ struct kvm_s390_vm_cpu_subfunc { > #define KVM_S390_VM_MIGRATION_START 1 > #define KVM_S390_VM_MIGRATION_STATUS 2 > > +/* kvm attributes for cpu topology */ > +#define KVM_S390_VM_CPU_TOPO_MTR_CLEAR 0 > +#define KVM_S390_VM_CPU_TOPO_MTR_SET 1 > + > /* for KVM_GET_REGS and KVM_SET_REGS */ > struct kvm_regs { > /* general purpose regs for s390 */ > diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c > index c8bdce31464f..80a1244f0ead 100644 > --- a/arch/s390/kvm/kvm-s390.c > +++ b/arch/s390/kvm/kvm-s390.c > @@ -1731,6 +1731,76 @@ static void kvm_s390_sca_set_mtcr(struct kvm *kvm) > ipte_unlock(kvm); > } > > +/** > + * kvm_s390_sca_clear_mtcr > + * @kvm: guest KVM description > + * > + * Is only relevant if the topology facility is present, > + * the caller should check KVM facility 11 > + * > + * Updates the Multiprocessor Topology-Change-Report to signal > + * the guest with a topology change. > + */ > +static void kvm_s390_sca_clear_mtcr(struct kvm *kvm) > +{ > + struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */ > + > + ipte_lock(kvm); > + sca->utility &= ~SCA_UTILITY_MTCR; One space too much. sca->utility &= ~SCA_UTILITY_MTCR; > + ipte_unlock(kvm); > +} > + > +static int kvm_s390_set_topology(struct kvm *kvm, struct kvm_device_attr *attr) > +{ > + if (!test_kvm_facility(kvm, 11)) > + return -ENXIO; > + > + switch (attr->attr) { > + case KVM_S390_VM_CPU_TOPO_MTR_SET: > + kvm_s390_sca_set_mtcr(kvm); > + break; > + case KVM_S390_VM_CPU_TOPO_MTR_CLEAR: > + kvm_s390_sca_clear_mtcr(kvm); > + break; > + } > + return 0; > +} > + > +/** > + * kvm_s390_sca_get_mtcr > + * @kvm: guest KVM description > + * > + * Is only relevant if the topology facility is present, > + * the caller should check KVM facility 11 > + * > + * reports to QEMU the Multiprocessor Topology-Change-Report. > + */ > +static int kvm_s390_sca_get_mtcr(struct kvm *kvm) > +{ > + struct bsca_block *sca = kvm->arch.sca; /* SCA version doesn't matter */ > + int val; > + > + ipte_lock(kvm); > + val = !!(sca->utility & SCA_UTILITY_MTCR); > + ipte_unlock(kvm); > + > + return val; > +} > + > +static int kvm_s390_get_topology(struct kvm *kvm, struct kvm_device_attr *attr) > +{ > + int mtcr; I think we prefer something like u16 when copying to user space. > + > + if (!test_kvm_facility(kvm, 11)) > + return -ENXIO; > + > + mtcr = kvm_s390_sca_get_mtcr(kvm); > + if (copy_to_user((void __user *)attr->addr, &mtcr, sizeof(mtcr))) > + return -EFAULT; > + > + return 0; > +} You should probably add documentation, and document that only the last bit (0x1) has a meaning. Apart from that LGTM. -- Thanks, David / dhildenb