From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628672805411207.55758032382755; Wed, 11 Aug 2021 02:06:45 -0700 (PDT) Received: from localhost ([::1]:40070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkCC-0005CO-4D for importer@patchew.org; Wed, 11 Aug 2021 05:06:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBC-0002yY-6R for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkB9-0007nb-UF for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-pYqcmA63NwenGTyJI2Vcww-1; Wed, 11 Aug 2021 05:05:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D52BE1853024; Wed, 11 Aug 2021 09:05:36 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id F03695B826; Wed, 11 Aug 2021 09:05:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672739; 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=+mS3O4POYnN7uAyASYwN1m7JdQo0LFcFpwPNpjhd3cs=; b=Nfj1johVbkupLwem8XqeG+Gvn0Yzqtcurjnnaz09k2b9eSUZx1sgacczmqPY5VIQVVihBN n2CmmKJ6oDs+7wYReb03lTP8sUkct7nqNehlz4syOYVFV0dvckt/xa1jFpeJEsdGZ0xsDQ t1AsP4g2N5rcsyDk0BMYO/W+kSLYY7U= X-MC-Unique: pYqcmA63NwenGTyJI2Vcww-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 01/13] s390x/tcg: wrap address for RRBE Date: Wed, 11 Aug 2021 11:05:15 +0200 Message-Id: <20210811090527.30556-2-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672807240100001 Content-Type: text/plain; charset="utf-8" Let's wrap the address just like for SSKE and ISKE. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/tcg/mem_helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 21a4de4067..e0befd0f03 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2223,11 +2223,12 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, = uint64_t r2) uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) { MachineState *ms =3D MACHINE(qdev_get_machine()); + uint64_t addr =3D wrap_address(env, r2); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint8_t re, key; =20 - if (r2 > ms->ram_size) { + if (addr > ms->ram_size) { return 0; } =20 @@ -2236,14 +2237,14 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t = r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, r2 / TARGET_PAGE_SIZE, 1, &key)) { + if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { return 0; } =20 re =3D key & (SK_R | SK_C); key &=3D ~SK_R; =20 - if (skeyclass->set_skeys(ss, r2 / TARGET_PAGE_SIZE, 1, &key)) { + if (skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { return 0; } /* --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628672927934656.6992150275938; Wed, 11 Aug 2021 02:08:47 -0700 (PDT) Received: from localhost ([::1]:48446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkEA-0002Pn-7d for importer@patchew.org; Wed, 11 Aug 2021 05:08:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBE-0002zU-MU for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBD-0007qM-5E for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-bTi3sBk6NfixosviLoAvYQ-1; Wed, 11 Aug 2021 05:05:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0FE51019629; Wed, 11 Aug 2021 09:05:39 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F5755B826; Wed, 11 Aug 2021 09:05:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672742; 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=zVmrBQcqY5jBbgaTEsCI13ymxgm1ptrCnTA6JG4uFYg=; b=dqrXmDBeXYxoiPPfangXzijZRZ74MIl0HEFYbuEod3bV4SSq7q65toyQLgBfhEDplYi7MR dJhReP24KEd/dju2Gg3Knf6ef6kkKnTXcvAoLkugDCNM9p6/iaXjE4oXg5wTHtGK1o+c3O TERFUwHFsBDpUnISHBA+8csp24ZSYBE= X-MC-Unique: bTi3sBk6NfixosviLoAvYQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 02/13] s390x/tcg: fix ignoring bit 63 when setting the storage key in SSKE Date: Wed, 11 Aug 2021 11:05:16 +0200 Message-Id: <20210811090527.30556-3-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672928991100001 Content-Type: text/plain; charset="utf-8" Right now we could set an 8-bit storage key via SSKE and retrieve it again via ISKE, which is against the architecture description: SSKE: " The new seven-bit storage-key value, or selected bits thereof, is obtained from bit positions 56-62 of gen- eral register R 1 . The contents of bit positions 0-55 and 63 of the register are ignored. " ISKE: " The seven-bit storage key is inserted in bit positions 56-62 of general register R 1 , and bit 63 is set to zero. " Let's properly ignore bit 63 to create the correct seven-bit storage key. Signed-off-by: David Hildenbrand --- target/s390x/tcg/mem_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index e0befd0f03..3c0820dd74 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2210,7 +2210,7 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - key =3D (uint8_t) r1; + key =3D r1 & 0xfe; skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); /* * As we can only flush by virtual address and not all the entries --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16286729337111019.5515431065023; Wed, 11 Aug 2021 02:08:53 -0700 (PDT) Received: from localhost ([::1]:48578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkEG-0002Uz-M6 for importer@patchew.org; Wed, 11 Aug 2021 05:08:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBI-00038Y-M9 for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26310) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBG-0007sN-44 for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-508-pSiXBXzgMDaAxTZpZ9_XCQ-1; Wed, 11 Aug 2021 05:05:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BB21801AE7; Wed, 11 Aug 2021 09:05:42 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D49B69CBA; Wed, 11 Aug 2021 09:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672744; 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=YlLcEK4sJhfTE3pXmaG2DvF6Zr1wwk/2u/lE+zkLEJ8=; b=OHJ6Nz7O6zYXHKEkzHgRouvDNfLvKs1u51hA3tqRtIa7FlniOz6/11Sp58BQ04VaQqN/z/ zK/hXeI5m90gAyRDTSg3QkMC6tXfkkHz9iGfixanhnwUrJpfYTHprtYzxKYqwpfTr9NQX/ T64KmVRUQOla+g5zJYsS5e3gcy4hsLU= X-MC-Unique: pSiXBXzgMDaAxTZpZ9_XCQ-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 03/13] s390x/tcg: convert real to absolute address for RRBE, SSKE and ISKE Date: Wed, 11 Aug 2021 11:05:17 +0200 Message-Id: <20210811090527.30556-4-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672935314100001 Content-Type: text/plain; charset="utf-8" For RRBE, SSKE, and ISKE, we're dealing with real addresses, so we have to convert to an absolute address first. In the future, when adding EDAT1 support, we'll have to pay attention to SSKE handling, as we'll be dealing with absolute addresses when the multiple-block control is one. Signed-off-by: David Hildenbrand --- target/s390x/tcg/mem_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 3c0820dd74..dd506d8d17 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2177,6 +2177,7 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) uint64_t addr =3D wrap_address(env, r2); uint8_t key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return 0; } @@ -2201,6 +2202,7 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) uint64_t addr =3D wrap_address(env, r2); uint8_t key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return; } @@ -2228,6 +2230,7 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) static S390SKeysClass *skeyclass; uint8_t re, key; =20 + addr =3D mmu_real2abs(env, addr); if (addr > ms->ram_size) { return 0; } --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673060901610.9373981127043; Wed, 11 Aug 2021 02:11:00 -0700 (PDT) Received: from localhost ([::1]:57328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkGJ-0008KM-Lk for importer@patchew.org; Wed, 11 Aug 2021 05:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBN-0003P2-Gq for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBK-0007xD-DC for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-34-hCdAxyWEOQSnYnpxGmyXUg-1; Wed, 11 Aug 2021 05:05:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84B52760C1; Wed, 11 Aug 2021 09:05:45 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBB6D5B826; Wed, 11 Aug 2021 09:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672749; 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=H8OQLRRjGN1hBvk4gCqD3cOLrsNiTe2K4NYF2vRivo8=; b=IjFVgKOPa4SGhQAG7gnLonhJNz8c12ArIxji8CxrqfT7movM29gzpYPHKF3wMYfy682Br0 QrJl1IVC5xp/z7fsKzuzjkT8gTd9SCBiIaXVqPJDNvRsr5MvG0iMzqVyiX3CWd3zB1nvu4 Gz94OTEV4doSgUp0YNeW0AC1LlqC/cg= X-MC-Unique: hCdAxyWEOQSnYnpxGmyXUg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 04/13] s390x/tcg: check for addressing exceptions for RRBE, SSKE and ISKE Date: Wed, 11 Aug 2021 11:05:18 +0200 Message-Id: <20210811090527.30556-5-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673061519100001 Content-Type: text/plain; charset="utf-8" Let's replace the ram_size check by a proper physical address space check (for example, to prepare for memory hotplug), trigger addressing exceptions and trace the return value of the storage key getter/setter. Provide an helper mmu_absolute_addr_valid() to be used in other context soon. Always test for "read" instead of "write" as we are not actually modifying the page itself. Signed-off-by: David Hildenbrand --- target/s390x/helper.h | 6 +++--- target/s390x/mmu_helper.c | 8 ++++++++ target/s390x/s390x-internal.h | 1 + target/s390x/tcg/mem_helper.c | 36 ++++++++++++++++++++++------------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/target/s390x/helper.h b/target/s390x/helper.h index 6215ca00bc..271b081e8c 100644 --- a/target/s390x/helper.h +++ b/target/s390x/helper.h @@ -336,9 +336,9 @@ DEF_HELPER_FLAGS_4(stctl, TCG_CALL_NO_WG, void, env, i3= 2, i64, i32) DEF_HELPER_FLAGS_4(stctg, TCG_CALL_NO_WG, void, env, i32, i64, i32) DEF_HELPER_FLAGS_2(testblock, TCG_CALL_NO_WG, i32, env, i64) DEF_HELPER_FLAGS_3(tprot, TCG_CALL_NO_WG, i32, env, i64, i64) -DEF_HELPER_FLAGS_2(iske, TCG_CALL_NO_RWG_SE, i64, env, i64) -DEF_HELPER_FLAGS_3(sske, TCG_CALL_NO_RWG, void, env, i64, i64) -DEF_HELPER_FLAGS_2(rrbe, TCG_CALL_NO_RWG, i32, env, i64) +DEF_HELPER_2(iske, i64, env, i64) +DEF_HELPER_3(sske, void, env, i64, i64) +DEF_HELPER_2(rrbe, i32, env, i64) DEF_HELPER_4(mvcs, i32, env, i64, i64, i64) DEF_HELPER_4(mvcp, i32, env, i64, i64, i64) DEF_HELPER_4(sigp, i32, env, i64, i32, i32) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index d779a9fc51..0620b1803e 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -94,6 +94,14 @@ target_ulong mmu_real2abs(CPUS390XState *env, target_ulo= ng raddr) return raddr; } =20 +bool mmu_absolute_addr_valid(target_ulong addr, bool is_write) +{ + return address_space_access_valid(&address_space_memory, + addr & TARGET_PAGE_MASK, + TARGET_PAGE_SIZE, is_write, + MEMTXATTRS_UNSPECIFIED); +} + static inline bool read_table_entry(CPUS390XState *env, hwaddr gaddr, uint64_t *entry) { diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 5506f185e8..d246d26b04 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -373,6 +373,7 @@ void probe_write_access(CPUS390XState *env, uint64_t ad= dr, uint64_t len, =20 =20 /* mmu_helper.c */ +bool mmu_absolute_addr_valid(target_ulong addr, bool is_write); int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, target_ulong *raddr, int *flags, uint64_t *tec); int mmu_translate_real(CPUS390XState *env, target_ulong raddr, int rw, diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index dd506d8d17..90ac82fdcc 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -28,6 +28,7 @@ #include "qemu/int128.h" #include "qemu/atomic128.h" #include "tcg/tcg.h" +#include "trace.h" =20 #if !defined(CONFIG_USER_ONLY) #include "hw/s390x/storage-keys.h" @@ -2171,15 +2172,15 @@ uint32_t HELPER(tprot)(CPUS390XState *env, uint64_t= a1, uint64_t a2) /* insert storage key extended */ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint64_t addr =3D wrap_address(env, r2); uint8_t key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return 0; + if (!mmu_absolute_addr_valid(addr, false)) { + trigger_pgm_exception(env, PGM_ADDRESSING); } =20 if (unlikely(!ss)) { @@ -2187,7 +2188,9 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_get_skeys_nonzero(rc); return 0; } return key; @@ -2196,15 +2199,15 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t = r2) /* set storage key extended */ void HELPER(sske)(CPUS390XState *env, uint64_t r1, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint64_t addr =3D wrap_address(env, r2); uint8_t key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return; + if (!mmu_absolute_addr_valid(addr, false)) { + trigger_pgm_exception(env, PGM_ADDRESSING); } =20 if (unlikely(!ss)) { @@ -2213,7 +2216,10 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, u= int64_t r2) } =20 key =3D r1 & 0xfe; - skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); + } /* * As we can only flush by virtual address and not all the entries * that point to a physical address we have to flush the whole TLB. @@ -2224,15 +2230,15 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, = uint64_t r2) /* reset reference bit extended */ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) { - MachineState *ms =3D MACHINE(qdev_get_machine()); uint64_t addr =3D wrap_address(env, r2); static S390SKeysState *ss; static S390SKeysClass *skeyclass; uint8_t re, key; + int rc; =20 addr =3D mmu_real2abs(env, addr); - if (addr > ms->ram_size) { - return 0; + if (!mmu_absolute_addr_valid(addr, false)) { + trigger_pgm_exception(env, PGM_ADDRESSING); } =20 if (unlikely(!ss)) { @@ -2240,14 +2246,18 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t = r2) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 - if (skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_get_skeys_nonzero(rc); return 0; } =20 re =3D key & (SK_R | SK_C); key &=3D ~SK_R; =20 - if (skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key)) { + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); return 0; } /* --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673170064352.0939062736726; Wed, 11 Aug 2021 02:12:50 -0700 (PDT) Received: from localhost ([::1]:35802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkI4-0004UI-VW for importer@patchew.org; Wed, 11 Aug 2021 05:12:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBO-0003S3-Tc for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:39621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBN-0007zI-Cb for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:54 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-9aXXXOHSPe2e0Z1-KmEFWA-1; Wed, 11 Aug 2021 05:05:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 78162101962B; Wed, 11 Aug 2021 09:05:50 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id D31EF620DE; Wed, 11 Aug 2021 09:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672752; 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=hjNWqno5cH2/vA9rO21bPb9HAnn1vYcvSEX3uK7XI20=; b=I3xe1mWRuhGTExFFteaMQO2HI0hB0le1uHecOH24bUJD1s3TfQtddla+7cdvUw/ZnrrPeM uugnfV5BmC+pQyzx8o8IObZ3XhuODrpS86Ofd0yxrj86/8w3AdBsDsrq5KZ0MMZjM1fmU2 qOnLVBZyBqV519iV/lXlQVpbdyv+yHw= X-MC-Unique: 9aXXXOHSPe2e0Z1-KmEFWA-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 05/13] s390x/mmu_helper: no need to pass access type to mmu_translate_asce() Date: Wed, 11 Aug 2021 11:05:19 +0200 Message-Id: <20210811090527.30556-6-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673170595100003 Content-Type: text/plain; charset="utf-8" The access type is unused since commit 81d7e3bc45 ("s390x/mmu: Inject DAT exceptions from a single place"). Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/mmu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index 0620b1803e..167f1b1455 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -125,7 +125,7 @@ static inline bool read_table_entry(CPUS390XState *env,= hwaddr gaddr, =20 static int mmu_translate_asce(CPUS390XState *env, target_ulong vaddr, uint64_t asc, uint64_t asce, target_ulong *r= addr, - int *flags, int rw) + int *flags) { const bool edat1 =3D (env->cregs[0] & CR0_EDAT) && s390_has_feat(S390_FEAT_EDAT); @@ -428,7 +428,7 @@ int mmu_translate(CPUS390XState *env, target_ulong vadd= r, int rw, uint64_t asc, } =20 /* perform the DAT translation */ - r =3D mmu_translate_asce(env, vaddr, asc, asce, raddr, flags, rw); + r =3D mmu_translate_asce(env, vaddr, asc, asce, raddr, flags); if (unlikely(r)) { return r; } --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673233181485.52443504316636; Wed, 11 Aug 2021 02:13:53 -0700 (PDT) Received: from localhost ([::1]:39844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkJ6-0007Cy-4w for importer@patchew.org; Wed, 11 Aug 2021 05:13:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBR-0003cN-MG for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBQ-00081J-5i for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:05:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-9wcpyUInMeK_V0qV2yzVxg-1; Wed, 11 Aug 2021 05:05:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D1C1801B3C; Wed, 11 Aug 2021 09:05:53 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6C355B826; Wed, 11 Aug 2021 09:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672755; 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=wiY5CmPNZqXMtJWZ/fgLd7xkq85LpX5IToi2MNmjMHg=; b=SjWpJzXtNhsDhItUdgLXnn20kPIP1ga+DcxvTDpTXnFLesW/Xj3P4QkEGLVnBTbFsi6CMP /mbw/ifl3DV4/eOYAKPEir4pH6fcKLl3Jbi6uMvmXrMtgIN2y10HIVSA5He2DALjMlIjM8 ryXkdF+DkZK4wJJfqRiclccMbbOZ9zo= X-MC-Unique: 9wcpyUInMeK_V0qV2yzVxg-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 06/13] s390x/mmu_helper: fixup mmu_translate() documentation Date: Wed, 11 Aug 2021 11:05:20 +0200 Message-Id: <20210811090527.30556-7-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673235008100001 Content-Type: text/plain; charset="utf-8" Looks like we forgot to adjust documentation of one parameter. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/mmu_helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index 167f1b1455..ca25dadb5b 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -374,7 +374,8 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) * @param asc address space control (one of the PSW_ASC_* modes) * @param raddr the translated address is stored to this pointer * @param flags the PAGE_READ/WRITE/EXEC flags are stored to this pointer - * @param exc true =3D inject a program check if a fault occurred + * @param tec the translation exception code if stored to this pointer = if + * there is an exception to raise * @return 0 =3D success, !=3D 0, the exception to raise */ int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162867283932664.10380834614705; Wed, 11 Aug 2021 02:07:19 -0700 (PDT) Received: from localhost ([::1]:42026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkCk-0006WQ-Ai for importer@patchew.org; Wed, 11 Aug 2021 05:07:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBV-0003or-D3 for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBT-00083I-BO for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:01 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-ZADBowcdMhWJAd00Qrnuqw-1; Wed, 11 Aug 2021 05:05:57 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5164F801A92; Wed, 11 Aug 2021 09:05:56 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6932604CC; Wed, 11 Aug 2021 09:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672758; 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=Ji09bpunfELJ4aZDBavd0LS9woJl2oCWbQQvuDDjQZA=; b=NpHWpBaChutNqHruwNAinecm7wh0jwAeeJm5FGfsUN3dowqD1vSFAd7l+DT3amkHc12408 7975latsWYGHRdOguf9X/Bu+IuAwg4R5BK6/HONdqZmqELN1oLOyIdFYhm5EvBTwIcROQU G6ida5VGjZhfqzn0OC9bfNWsDCgy3pY= X-MC-Unique: ZADBowcdMhWJAd00Qrnuqw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 07/13] s390x/mmu_helper: move address validation into mmu_translate*() Date: Wed, 11 Aug 2021 11:05:21 +0200 Message-Id: <20210811090527.30556-8-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672841121100001 Content-Type: text/plain; charset="utf-8" Let's move address validation into mmu_translate() and mmu_translate_real(). This allows for checking whether an absolute address is valid before looking up the storage key. We can now get rid of the ram_size check. Interestingly, we're already handling LOAD REAL ADDRESS wrong, because a) We're not supposed to touch storage keys b) We're not supposed to convert to an absolute address Let's use a fake, negative MMUAccessType to teach mmu_translate() to fix that handling and to not perform address validation. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/mmu_helper.c | 36 ++++++++++++++++++++-------------- target/s390x/s390x-internal.h | 2 ++ target/s390x/tcg/excp_helper.c | 13 ------------ target/s390x/tcg/mem_helper.c | 2 +- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index ca25dadb5b..de6df928d2 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -301,14 +301,13 @@ static void mmu_handle_skey(target_ulong addr, int rw= , int *flags) { static S390SKeysClass *skeyclass; static S390SKeysState *ss; - MachineState *ms =3D MACHINE(qdev_get_machine()); uint8_t key; int rc; =20 - if (unlikely(addr >=3D ms->ram_size)) { - return; - } - + /* + * We expect to be called with an absolute address that has already be= en + * validated, such that we can reliably use it to lookup the storage k= ey. + */ if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); @@ -370,7 +369,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) /** * Translate a virtual (logical) address into a physical (absolute) addres= s. * @param vaddr the virtual address - * @param rw 0 =3D read, 1 =3D write, 2 =3D code fetch + * @param rw 0 =3D read, 1 =3D write, 2 =3D code fetch, < 0 =3D load r= eal address * @param asc address space control (one of the PSW_ASC_* modes) * @param raddr the translated address is stored to this pointer * @param flags the PAGE_READ/WRITE/EXEC flags are stored to this pointer @@ -449,10 +448,17 @@ int mmu_translate(CPUS390XState *env, target_ulong va= ddr, int rw, uint64_t asc, } =20 nodat: - /* Convert real address -> absolute address */ - *raddr =3D mmu_real2abs(env, *raddr); + if (rw >=3D 0) { + /* Convert real address -> absolute address */ + *raddr =3D mmu_real2abs(env, *raddr); =20 - mmu_handle_skey(*raddr, rw, flags); + if (!mmu_absolute_addr_valid(*raddr, rw =3D=3D MMU_DATA_STORE)) { + *tec =3D 0; /* unused */ + return PGM_ADDRESSING; + } + + mmu_handle_skey(*raddr, rw, flags); + } return 0; } =20 @@ -473,12 +479,6 @@ static int translate_pages(S390CPU *cpu, vaddr addr, i= nt nr_pages, if (ret) { return ret; } - if (!address_space_access_valid(&address_space_memory, pages[i], - TARGET_PAGE_SIZE, is_write, - MEMTXATTRS_UNSPECIFIED)) { - *tec =3D 0; /* unused */ - return PGM_ADDRESSING; - } addr +=3D TARGET_PAGE_SIZE; } =20 @@ -588,6 +588,12 @@ int mmu_translate_real(CPUS390XState *env, target_ulon= g raddr, int rw, =20 *addr =3D mmu_real2abs(env, raddr & TARGET_PAGE_MASK); =20 + if (!mmu_absolute_addr_valid(*addr, rw =3D=3D MMU_DATA_STORE)) { + /* unused */ + *tec =3D 0; + return PGM_ADDRESSING; + } + mmu_handle_skey(*addr, rw, flags); return 0; } diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index d246d26b04..7a6aa4dacc 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -374,6 +374,8 @@ void probe_write_access(CPUS390XState *env, uint64_t ad= dr, uint64_t len, =20 /* mmu_helper.c */ bool mmu_absolute_addr_valid(target_ulong addr, bool is_write); +/* Special access mode only valid for mmu_translate() */ +#define MMU_S390_LRA -1 int mmu_translate(CPUS390XState *env, target_ulong vaddr, int rw, uint64_t= asc, target_ulong *raddr, int *flags, uint64_t *tec); int mmu_translate_real(CPUS390XState *env, target_ulong raddr, int rw, diff --git a/target/s390x/tcg/excp_helper.c b/target/s390x/tcg/excp_helper.c index a61917d04f..3d6662a53c 100644 --- a/target/s390x/tcg/excp_helper.c +++ b/target/s390x/tcg/excp_helper.c @@ -150,19 +150,6 @@ bool s390_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, g_assert_not_reached(); } =20 - /* check out of RAM access */ - if (!excp && - !address_space_access_valid(&address_space_memory, raddr, - TARGET_PAGE_SIZE, access_type, - MEMTXATTRS_UNSPECIFIED)) { - MachineState *ms =3D MACHINE(qdev_get_machine()); - qemu_log_mask(CPU_LOG_MMU, - "%s: raddr %" PRIx64 " > ram_size %" PRIx64 "\n", - __func__, (uint64_t)raddr, (uint64_t)ms->ram_size); - excp =3D PGM_ADDRESSING; - tec =3D 0; /* unused */ - } - env->tlb_fill_exc =3D excp; env->tlb_fill_tec =3D tec; =20 diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 90ac82fdcc..694c0aae63 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2455,7 +2455,7 @@ uint64_t HELPER(lra)(CPUS390XState *env, uint64_t add= r) tcg_s390_program_interrupt(env, PGM_SPECIAL_OP, GETPC()); } =20 - exc =3D mmu_translate(env, addr, 0, asc, &ret, &flags, &tec); + exc =3D mmu_translate(env, addr, MMU_S390_LRA, asc, &ret, &flags, &tec= ); if (exc) { cc =3D 3; ret =3D exc | 0x80000000; --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162867306372857.622242065927026; Wed, 11 Aug 2021 02:11:03 -0700 (PDT) Received: from localhost ([::1]:57408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkGL-0008OY-FE for importer@patchew.org; Wed, 11 Aug 2021 05:11:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBc-0004Ba-7f for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBa-00088F-Pk for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-kDpek6OlPVKqq2K4cvu8Uw-1; Wed, 11 Aug 2021 05:06:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95ABC1019623; Wed, 11 Aug 2021 09:06:01 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEAF95B4BC; Wed, 11 Aug 2021 09:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672766; 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=koATax0ENfqN19XtTaC7VpmNCcm6q32Nu4FPP5NnrNA=; b=TGck/vg5AQbBWgk62UdUDcYhZSlI0X2fZmvEwh1rYpQ3jlVL8mBiFtEIRHDBZWoXwOkgYQ u5ue29OhKF2pxrKfRzibzrWC3sUOD7q8ArBxgyxt0O+abHN9PZnUbEFGHdMbP16ZpKymy7 3buXJB61E/rICetDn2LhrfKUCSnRtbg= X-MC-Unique: kDpek6OlPVKqq2K4cvu8Uw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 08/13] s390x/mmu_helper: avoid setting the storage key if nothing changed Date: Wed, 11 Aug 2021 11:05:22 +0200 Message-Id: <20210811090527.30556-9-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673065889100001 Content-Type: text/plain; charset="utf-8" Avoid setting the key if nothing changed. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- target/s390x/mmu_helper.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index de6df928d2..e2b372efd9 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -301,7 +301,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) { static S390SKeysClass *skeyclass; static S390SKeysState *ss; - uint8_t key; + uint8_t key, old_key; int rc; =20 /* @@ -337,6 +337,7 @@ static void mmu_handle_skey(target_ulong addr, int rw, = int *flags) trace_get_skeys_nonzero(rc); return; } + old_key =3D key; =20 switch (rw) { case MMU_DATA_LOAD: @@ -360,9 +361,11 @@ static void mmu_handle_skey(target_ulong addr, int rw,= int *flags) /* Any store/fetch sets the reference bit */ key |=3D SK_R; =20 - rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); - if (rc) { - trace_set_skeys_nonzero(rc); + if (key !=3D old_key) { + rc =3D skeyclass->set_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); + if (rc) { + trace_set_skeys_nonzero(rc); + } } } =20 --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673293719737.7936957374459; Wed, 11 Aug 2021 02:14:53 -0700 (PDT) Received: from localhost ([::1]:42034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkK4-0000FX-HH for importer@patchew.org; Wed, 11 Aug 2021 05:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBg-0004RQ-FJ for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBe-0008BU-Tr for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-2-CdeVMu9bM_iaP04B6zjU1w-1; Wed, 11 Aug 2021 05:06:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E865A107ACF5; Wed, 11 Aug 2021 09:06:05 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id E02F0604CC; Wed, 11 Aug 2021 09:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672770; 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=ch4WEy/V4uQyl1wtK/EuX1zIoN7+7TlM+yYOWkAUt4Q=; b=hhlmFd9WmS6755YhbXxFzISYTHPfUxBxAuRPiAVEHWuPYRaetRbgsegMfIaHKDBaA42j09 e0Nly6PZip5gxOTQOiqDQPfSXWqZ2GZQEB3u47SJoZnF6r7u/3LF6OBcsg8LU+iwBZUeTW wmPzwJYELyNRSPVsHivSy5UYRzAeivw= X-MC-Unique: CdeVMu9bM_iaP04B6zjU1w-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 09/13] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to migrate Date: Wed, 11 Aug 2021 11:05:23 +0200 Message-Id: <20210811090527.30556-10-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673295636100001 Content-Type: text/plain; charset="utf-8" Let's use the guest_phys_blocks API to get physical memory regions that are well defined inside our physical address space and migrate the storage keys of these. This is a preparation for having memory besides initial ram defined in the guest physical address space, for example, via memory devices. We get rid of the ms->ram_size dependency. Please note that we will usually have very little (--> 1) physical ranges. With virtio-mem might have significantly more ranges in the future. If that turns out to be a problem (e.g., total memory footprint of the list), we could look into a memory mapping API that avoids creation of a list and instead triggers a callback for each range. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys.c | 70 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 9a8d60d1d9..250685a95a 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -17,6 +17,7 @@ #include "qapi/qapi-commands-misc-target.h" #include "qapi/qmp/qdict.h" #include "qemu/error-report.h" +#include "sysemu/memory_mapping.h" #include "sysemu/kvm.h" #include "migration/qemu-file-types.h" #include "migration/register.h" @@ -257,10 +258,9 @@ static void s390_storage_keys_save(QEMUFile *f, void *= opaque) { S390SKeysState *ss =3D S390_SKEYS(opaque); S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); - MachineState *ms =3D MACHINE(qdev_get_machine()); - uint64_t pages_left =3D ms->ram_size / TARGET_PAGE_SIZE; - uint64_t read_count, eos =3D S390_SKEYS_SAVE_FLAG_EOS; - vaddr cur_gfn =3D 0; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; + uint64_t pages, gfn; int error =3D 0; uint8_t *buf; =20 @@ -274,36 +274,52 @@ static void s390_storage_keys_save(QEMUFile *f, void = *opaque) goto end_stream; } =20 - /* We only support initial memory. Standby memory is not handled yet. = */ - qemu_put_be64(f, (cur_gfn * TARGET_PAGE_SIZE) | S390_SKEYS_SAVE_FLAG_S= KEYS); - qemu_put_be64(f, pages_left); - - while (pages_left) { - read_count =3D MIN(pages_left, S390_SKEYS_BUFFER_SIZE); - - if (!error) { - error =3D skeyclass->get_skeys(ss, cur_gfn, read_count, buf); - if (error) { - /* - * If error: we want to fill the stream with valid data in= stead - * of stopping early so we pad the stream with 0x00 values= and - * use S390_SKEYS_SAVE_FLAG_ERROR to indicate failure to t= he - * reading side. - */ - error_report("S390_GET_KEYS error %d", error); - memset(buf, 0, S390_SKEYS_BUFFER_SIZE); - eos =3D S390_SKEYS_SAVE_FLAG_ERROR; + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); + + /* Send each contiguous physical memory range separately. */ + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); + + gfn =3D block->target_start / TARGET_PAGE_SIZE; + pages =3D (block->target_end - block->target_start) / TARGET_PAGE_= SIZE; + qemu_put_be64(f, block->target_start | S390_SKEYS_SAVE_FLAG_SKEYS); + qemu_put_be64(f, pages); + + while (pages) { + const uint64_t cur_pages =3D MIN(pages, S390_SKEYS_BUFFER_SIZE= ); + + if (!error) { + error =3D skeyclass->get_skeys(ss, gfn, cur_pages, buf); + if (error) { + /* + * Create a valid stream with all 0x00 and indicate + * S390_SKEYS_SAVE_FLAG_ERROR to the destination. + */ + error_report("S390_GET_KEYS error %d", error); + memset(buf, 0, S390_SKEYS_BUFFER_SIZE); + } } + + qemu_put_buffer(f, buf, cur_pages); + gfn +=3D cur_pages; + pages -=3D cur_pages; } =20 - qemu_put_buffer(f, buf, read_count); - cur_gfn +=3D read_count; - pages_left -=3D read_count; + if (error) { + break; + } } =20 + guest_phys_blocks_free(&guest_phys_blocks); g_free(buf); end_stream: - qemu_put_be64(f, eos); + if (error) { + qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_ERROR); + } else { + qemu_put_be64(f, S390_SKEYS_SAVE_FLAG_EOS); + } } =20 static int s390_storage_keys_load(QEMUFile *f, void *opaque, int version_i= d) --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628672964863907.8744202360587; Wed, 11 Aug 2021 02:09:24 -0700 (PDT) Received: from localhost ([::1]:50608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkEl-0003pp-Oq for importer@patchew.org; Wed, 11 Aug 2021 05:09:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBl-0004ka-My for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBj-0008Ep-PM for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-_TAVO9VSNWq3cvxXyc3yxw-1; Wed, 11 Aug 2021 05:06:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3241A87D54A; Wed, 11 Aug 2021 09:06:12 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 539CB69CBA; Wed, 11 Aug 2021 09:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672775; 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=kziqgMymkMLtY5poKAOZZqOtzjY64iw5zYUWpNorWmw=; b=E3MbGG6CAPT6ySjIiiBFSmSU3lD5lBlK8MDNdaPFLhjg3SyuWGLKZtvlZ66gpXbf9korqI i99vpXOLfyAKybL2o34FzLZsdQMSIH9adBE9S+6QEpqO9ikuZyCkcmDoDkm0w/2ijAHmdj M9bNfkX/8xB0XhzAzlX8HJR4D6SFtt0= X-MC-Unique: _TAVO9VSNWq3cvxXyc3yxw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 10/13] hw/s390x/s390-skeys: use memory mapping to detect which storage keys to dump Date: Wed, 11 Aug 2021 11:05:24 +0200 Message-Id: <20210811090527.30556-11-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672966176100001 Content-Type: text/plain; charset="utf-8" Handle it similar to migration. Assert that we're holding the BQL, to make sure we don't see concurrent modifications. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys.c | 50 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 250685a95a..56a47fe180 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -110,11 +110,10 @@ void qmp_dump_skeys(const char *filename, Error **err= p) { S390SKeysState *ss =3D s390_get_skeys_device(); S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); - MachineState *ms =3D MACHINE(qdev_get_machine()); - const uint64_t total_count =3D ms->ram_size / TARGET_PAGE_SIZE; - uint64_t handled_count =3D 0, cur_count; + GuestPhysBlockList guest_phys_blocks; + GuestPhysBlock *block; + uint64_t pages, gfn; Error *lerr =3D NULL; - vaddr cur_gfn =3D 0; uint8_t *buf; int ret; int fd; @@ -145,28 +144,39 @@ void qmp_dump_skeys(const char *filename, Error **err= p) goto out; } =20 - /* we'll only dump initial memory for now */ - while (handled_count < total_count) { - /* Calculate how many keys to ask for & handle overflow case */ - cur_count =3D MIN(total_count - handled_count, S390_SKEYS_BUFFER_S= IZE); + assert(qemu_mutex_iothread_locked()); + guest_phys_blocks_init(&guest_phys_blocks); + guest_phys_blocks_append(&guest_phys_blocks); =20 - ret =3D skeyclass->get_skeys(ss, cur_gfn, cur_count, buf); - if (ret < 0) { - error_setg(errp, "get_keys error %d", ret); - goto out_free; - } + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { + assert(QEMU_IS_ALIGNED(block->target_start, TARGET_PAGE_SIZE)); + assert(QEMU_IS_ALIGNED(block->target_end, TARGET_PAGE_SIZE)); =20 - /* write keys to stream */ - write_keys(f, buf, cur_gfn, cur_count, &lerr); - if (lerr) { - goto out_free; - } + gfn =3D block->target_start / TARGET_PAGE_SIZE; + pages =3D (block->target_end - block->target_start) / TARGET_PAGE_= SIZE; =20 - cur_gfn +=3D cur_count; - handled_count +=3D cur_count; + while (pages) { + const uint64_t cur_pages =3D MIN(pages, S390_SKEYS_BUFFER_SIZE= ); + + ret =3D skeyclass->get_skeys(ss, gfn, cur_pages, buf); + if (ret < 0) { + error_setg_errno(errp, -ret, "get_keys error"); + goto out_free; + } + + /* write keys to stream */ + write_keys(f, buf, gfn, cur_pages, &lerr); + if (lerr) { + goto out_free; + } + + gfn +=3D cur_pages; + pages -=3D cur_pages; + } } =20 out_free: + guest_phys_blocks_free(&guest_phys_blocks); error_propagate(errp, lerr); g_free(buf); out: --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628672870178954.0410650728569; Wed, 11 Aug 2021 02:07:50 -0700 (PDT) Received: from localhost ([::1]:43758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkDF-0007gw-3Z for importer@patchew.org; Wed, 11 Aug 2021 05:07:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBo-0004so-37 for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:26907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBl-0008Gi-Qp for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-SFxWEgKsMIKPcqE7ZIbz0Q-1; Wed, 11 Aug 2021 05:06:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 104B9185302D; Wed, 11 Aug 2021 09:06:15 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9175A604CC; Wed, 11 Aug 2021 09:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672777; 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=hvXtWV7uKYaC3yADNUWplnYXFVfQJU9iG6ABZ6uLVG4=; b=Og9tf2JEGAiPLakNDWQQuPxQ+G//Ev96vhocTv5imTD3bSdb4bPDERx/Fcf/11sVXQHuRG 7MmdCkWW1nyKYcmTbPv1OxK5BrEyw48hjOS+EIZZgphZ0YqdQEVl7LqURfb4WcAccF4/rx ZTUbKuOxYaBr7z3an+hKsKxR+WfwvK8= X-MC-Unique: SFxWEgKsMIKPcqE7ZIbz0Q-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 11/13] hw/s390x/s390-skeys: check if an address is valid before dumping the key Date: Wed, 11 Aug 2021 11:05:25 +0200 Message-Id: <20210811090527.30556-12-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628672871914100001 Content-Type: text/plain; charset="utf-8" Let's validate the given address and report a proper error in case it's not. All call paths now properly check the validity of the given GFN. Remove the TODO. The errors inside the getter and setter should only trigger if something really goes wrong now, for example, with a broken migration stream. Or when we forget to update the storage key allocation with memory hotplug. Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 56a47fe180..db73e9091d 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -18,6 +18,7 @@ #include "qapi/qmp/qdict.h" #include "qemu/error-report.h" #include "sysemu/memory_mapping.h" +#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "migration/qemu-file-types.h" #include "migration/register.h" @@ -86,6 +87,13 @@ void hmp_info_skeys(Monitor *mon, const QDict *qdict) return; } =20 + if (!address_space_access_valid(&address_space_memory, + addr & TARGET_PAGE_MASK, TARGET_PAGE_S= IZE, + false, MEMTXATTRS_UNSPECIFIED)) { + monitor_printf(mon, "Error: The given address is not valid\n"); + return; + } + r =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); if (r < 0) { monitor_printf(mon, "Error: %s\n", strerror(-r)); @@ -197,11 +205,6 @@ static int qemu_s390_skeys_enabled(S390SKeysState *ss) return 1; } =20 -/* - * TODO: for memory hotplug support qemu_s390_skeys_set and qemu_s390_skey= s_get - * will have to make sure that the given gfn belongs to a memory region an= d not - * a memory hole. - */ static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, uint64_t count, uint8_t *keys) { --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673110357415.6911801361522; Wed, 11 Aug 2021 02:11:50 -0700 (PDT) Received: from localhost ([::1]:59056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkH6-0001Bm-Ji for importer@patchew.org; Wed, 11 Aug 2021 05:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBr-00055P-6V for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47274) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBp-0008Ic-FA for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-535-ULnfdBMxP0ydnWFI32nE3A-1; Wed, 11 Aug 2021 05:06:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21DAE800EB8; Wed, 11 Aug 2021 09:06:18 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F21E5B4BC; Wed, 11 Aug 2021 09:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672780; 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=lTI1+D+SnN9eJYRwGvcqKaY5n2BrWD0pbmIa58pib0Q=; b=jJ4e+Akf21pUm7Zr/NzozTY23vqQbEenP++iAL8GcS22kKwzEZiaUYZ9EfIveWXtt+OcGU 7/9CM7Z3VwA9bUxmdQwyCn67Lv93WDa8xXp9S0+VJlslCEKA8EWOih1QOqd815oWBcsnr4 U4+ItF+SUvmQjUsbPpzIZtDI8zNmCek= X-MC-Unique: ULnfdBMxP0ydnWFI32nE3A-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 12/13] hw/s390x/s390-skeys: rename skeys_enabled to skeys_are_enabled Date: Wed, 11 Aug 2021 11:05:26 +0200 Message-Id: <20210811090527.30556-13-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673112247100001 Content-Type: text/plain; charset="utf-8" ... and make it return a bool instead. Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys-kvm.c | 4 ++-- hw/s390x/s390-skeys.c | 12 ++++++------ include/hw/s390x/storage-keys.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hw/s390x/s390-skeys-kvm.c b/hw/s390x/s390-skeys-kvm.c index 1c4d805ad8..3ff9d94b80 100644 --- a/hw/s390x/s390-skeys-kvm.c +++ b/hw/s390x/s390-skeys-kvm.c @@ -15,7 +15,7 @@ #include "qemu/error-report.h" #include "qemu/module.h" =20 -static int kvm_s390_skeys_enabled(S390SKeysState *ss) +static bool kvm_s390_skeys_are_enabled(S390SKeysState *ss) { S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); uint8_t single_key; @@ -57,7 +57,7 @@ static void kvm_s390_skeys_class_init(ObjectClass *oc, vo= id *data) S390SKeysClass *skeyclass =3D S390_SKEYS_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 - skeyclass->skeys_enabled =3D kvm_s390_skeys_enabled; + skeyclass->skeys_are_enabled =3D kvm_s390_skeys_are_enabled; skeyclass->get_skeys =3D kvm_s390_skeys_get; skeyclass->set_skeys =3D kvm_s390_skeys_set; =20 diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index db73e9091d..9e994a5582 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -82,7 +82,7 @@ void hmp_info_skeys(Monitor *mon, const QDict *qdict) int r; =20 /* Quick check to see if guest is using storage keys*/ - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { monitor_printf(mon, "Error: This guest is not using storage keys\n= "); return; } @@ -128,7 +128,7 @@ void qmp_dump_skeys(const char *filename, Error **errp) FILE *f; =20 /* Quick check to see if guest is using storage keys*/ - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { error_setg(errp, "This guest is not using storage keys - " "nothing to dump"); return; @@ -200,9 +200,9 @@ static void qemu_s390_skeys_init(Object *obj) skeys->keydata =3D g_malloc0(skeys->key_count); } =20 -static int qemu_s390_skeys_enabled(S390SKeysState *ss) +static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) { - return 1; + return true; } =20 static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, @@ -250,7 +250,7 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) S390SKeysClass *skeyclass =3D S390_SKEYS_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); =20 - skeyclass->skeys_enabled =3D qemu_s390_skeys_enabled; + skeyclass->skeys_are_enabled =3D qemu_s390_skeys_are_enabled; skeyclass->get_skeys =3D qemu_s390_skeys_get; skeyclass->set_skeys =3D qemu_s390_skeys_set; =20 @@ -277,7 +277,7 @@ static void s390_storage_keys_save(QEMUFile *f, void *o= paque) int error =3D 0; uint8_t *buf; =20 - if (!skeyclass->skeys_enabled(ss)) { + if (!skeyclass->skeys_are_enabled(ss)) { goto end_stream; } =20 diff --git a/include/hw/s390x/storage-keys.h b/include/hw/s390x/storage-key= s.h index 2888d42d0b..eb091842c8 100644 --- a/include/hw/s390x/storage-keys.h +++ b/include/hw/s390x/storage-keys.h @@ -28,7 +28,7 @@ struct S390SKeysState { =20 struct S390SKeysClass { DeviceClass parent_class; - int (*skeys_enabled)(S390SKeysState *ks); + bool (*skeys_are_enabled)(S390SKeysState *ks); int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, --=20 2.31.1 From nobody Sun May 19 12:26:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1628673171555485.4100356477676; Wed, 11 Aug 2021 02:12:51 -0700 (PDT) Received: from localhost ([::1]:35884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mDkI6-0004Xb-EJ for importer@patchew.org; Wed, 11 Aug 2021 05:12:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBw-0005Sw-N9 for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mDkBu-0008Oy-GP for qemu-devel@nongnu.org; Wed, 11 Aug 2021 05:06:28 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-sWUlDtlmOC-cQSQ9l2VnKw-1; Wed, 11 Aug 2021 05:06:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8C20760C8; Wed, 11 Aug 2021 09:06:20 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76DA05B4BC; Wed, 11 Aug 2021 09:06:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628672785; 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=aFlw3OL8KwlapGhHLerxFvpJQaR+1BRwiTcrhlMJvYw=; b=FPnFUePtTLv/kyDH01ja7ql6ju0O6pAdiOeCoJEnkKjndf6CPdI7BCDFAySStgF7Ne8YmW 72j6EmUsqdCA/iJXTtyNzE3lzQbVSIcoVq283TrK3eKJ14fXi8HW5emfvQXQ9P7S+9whsb Ds2bAjjpiTonSHbN7PztNxHFw69ujI4= X-MC-Unique: sWUlDtlmOC-cQSQ9l2VnKw-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH v2 13/13] hw/s390x/s390-skeys: lazy storage key enablement under TCG Date: Wed, 11 Aug 2021 11:05:27 +0200 Message-Id: <20210811090527.30556-14-david@redhat.com> In-Reply-To: <20210811090527.30556-1-david@redhat.com> References: <20210811090527.30556-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.704, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jason J . Herne" , Thomas Huth , Janosch Frank , David Hildenbrand , Cornelia Huck , Richard Henderson , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1628673172966100001 Content-Type: text/plain; charset="utf-8" Let's enable storage keys lazily under TCG, just as we do under KVM. Only fairly old Linux versions actually make use of storage keys, so it can be kind of wasteful to allocate quite some memory and track changes and references if nobody cares. We have to make sure to flush the TLB when enabling storage keys after the VM was already running: otherwise it might happen that we don't catch references or modifications afterwards. Add proper documentation to all callbacks. The kvm-unit-tests skey tests keeps on working with this change. Signed-off-by: David Hildenbrand --- hw/s390x/s390-skeys.c | 65 ++++++++++++++++++++++++++------- include/hw/s390x/storage-keys.h | 63 ++++++++++++++++++++++++++++++++ target/s390x/mmu_helper.c | 8 ++++ target/s390x/tcg/mem_helper.c | 9 +++++ 4 files changed, 131 insertions(+), 14 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 9e994a5582..5024faf411 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -191,18 +191,45 @@ out: fclose(f); } =20 -static void qemu_s390_skeys_init(Object *obj) +static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) { - QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(obj); - MachineState *machine =3D MACHINE(qdev_get_machine()); + QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(ss); =20 - skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; - skeys->keydata =3D g_malloc0(skeys->key_count); + /* Lockless check is sufficient. */ + return !!skeys->keydata; } =20 -static bool qemu_s390_skeys_are_enabled(S390SKeysState *ss) +static bool qemu_s390_enable_skeys(S390SKeysState *ss) { - return true; + QEMUS390SKeysState *skeys =3D QEMU_S390_SKEYS(ss); + static gsize initialized; + + if (likely(skeys->keydata)) { + return true; + } + + /* + * TODO: Modern Linux doesn't use storage keys unless running KVM gues= ts + * that use storage keys. Therefore, we keep it simple for now. + * + * 1) We should initialize to "referenced+changed" for an initial + * over-indication. Let's avoid touching megabytes of data for now = and + * assume that any sane user will issue a storage key instruction b= efore + * actually relying on this data. + * 2) Relying on ram_size and allocating a big array is ugly. We should + * allocate and manage storage key data per RAMBlock or optimally u= sing + * some sparse data structure. + * 3) We only ever have a single S390SKeysState, so relying on + * g_once_init_enter() is good enough. + */ + if (g_once_init_enter(&initialized)) { + MachineState *machine =3D MACHINE(qdev_get_machine()); + + skeys->key_count =3D machine->ram_size / TARGET_PAGE_SIZE; + skeys->keydata =3D g_malloc0(skeys->key_count); + g_once_init_leave(&initialized, 1); + } + return false; } =20 static int qemu_s390_skeys_set(S390SKeysState *ss, uint64_t start_gfn, @@ -212,9 +239,10 @@ static int qemu_s390_skeys_set(S390SKeysState *ss, uin= t64_t start_gfn, int i; =20 /* Check for uint64 overflow and access beyond end of key data */ - if (start_gfn + count > skeydev->key_count || start_gfn + count < coun= t) { - error_report("Error: Setting storage keys for page beyond the end " - "of memory: gfn=3D%" PRIx64 " count=3D%" PRId64, + if (unlikely(!skeydev->keydata || start_gfn + count > skeydev->key_cou= nt || + start_gfn + count < count)) { + error_report("Error: Setting storage keys for pages with unallocat= ed " + "storage key memory: gfn=3D%" PRIx64 " count=3D%" PRI= d64, start_gfn, count); return -EINVAL; } @@ -232,9 +260,10 @@ static int qemu_s390_skeys_get(S390SKeysState *ss, uin= t64_t start_gfn, int i; =20 /* Check for uint64 overflow and access beyond end of key data */ - if (start_gfn + count > skeydev->key_count || start_gfn + count < coun= t) { - error_report("Error: Getting storage keys for page beyond the end " - "of memory: gfn=3D%" PRIx64 " count=3D%" PRId64, + if (unlikely(!skeydev->keydata || start_gfn + count > skeydev->key_cou= nt || + start_gfn + count < count)) { + error_report("Error: Getting storage keys for pages with unallocat= ed " + "storage key memory: gfn=3D%" PRIx64 " count=3D%" PRI= d64, start_gfn, count); return -EINVAL; } @@ -251,6 +280,7 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) DeviceClass *dc =3D DEVICE_CLASS(oc); =20 skeyclass->skeys_are_enabled =3D qemu_s390_skeys_are_enabled; + skeyclass->enable_skeys =3D qemu_s390_enable_skeys; skeyclass->get_skeys =3D qemu_s390_skeys_get; skeyclass->set_skeys =3D qemu_s390_skeys_set; =20 @@ -261,7 +291,6 @@ static void qemu_s390_skeys_class_init(ObjectClass *oc,= void *data) static const TypeInfo qemu_s390_skeys_info =3D { .name =3D TYPE_QEMU_S390_SKEYS, .parent =3D TYPE_S390_SKEYS, - .instance_init =3D qemu_s390_skeys_init, .instance_size =3D sizeof(QEMUS390SKeysState), .class_init =3D qemu_s390_skeys_class_init, .class_size =3D sizeof(S390SKeysClass), @@ -341,6 +370,14 @@ static int s390_storage_keys_load(QEMUFile *f, void *o= paque, int version_id) S390SKeysClass *skeyclass =3D S390_SKEYS_GET_CLASS(ss); int ret =3D 0; =20 + /* + * Make sure to lazy-enable if required to be done explicitly. No need= to + * flush any TLB as the VM is not running yet. + */ + if (skeyclass->enable_skeys) { + skeyclass->enable_skeys(ss); + } + while (!ret) { ram_addr_t addr; int flags; diff --git a/include/hw/s390x/storage-keys.h b/include/hw/s390x/storage-key= s.h index eb091842c8..aa2ec2aae5 100644 --- a/include/hw/s390x/storage-keys.h +++ b/include/hw/s390x/storage-keys.h @@ -28,9 +28,72 @@ struct S390SKeysState { =20 struct S390SKeysClass { DeviceClass parent_class; + + /** + * @skeys_are_enabled: + * + * Check whether storage keys are enabled. If not enabled, they were n= ot + * enabled lazily either by the guest via a storage key instruction or + * by the host during migration. + * + * If disabled, everything not explicitly triggered by the guest, + * such as outgoing migration or dirty/change tracking, should not tou= ch + * storage keys and should not lazily enable it. + * + * @ks: the #S390SKeysState + * + * Returns false if not enabled and true if enabled. + */ bool (*skeys_are_enabled)(S390SKeysState *ks); + + /** + * @enable_skeys: + * + * Lazily enable storage keys. If this function is not implemented, + * setting a storage key will lazily enable storage keys implicitly + * instead. TCG guests have to make sure to flush the TLB of all CPUs + * if storage keys were not enabled before this call. + * + * @ks: the #S390SKeysState + * + * Returns false if not enabled before this call, and true if already + * enabled. + */ + bool (*enable_skeys)(S390SKeysState *ks); + + /** + * @get_skeys: + * + * Get storage keys for the given PFN range. This call will fail if + * storage keys have not been lazily enabled yet. + * + * Callers have to validate that a GFN is valid before this call. + * + * @ks: the #S390SKeysState + * @start_gfn: the start GFN to get storage keys for + * @count: the number of storage keys to get + * @keys: the byte array where storage keys will be stored to + * + * Returns 0 on success, returns an error if getting a storage key fai= led. + */ int (*get_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); + /** + * @set_skeys: + * + * Set storage keys for the given PFN range. This call will fail if + * storage keys have not been lazily enabled yet and implicit + * enablement is not supported. + * + * Callers have to validate that a GFN is valid before this call. + * + * @ks: the #S390SKeysState + * @start_gfn: the start GFN to set storage keys for + * @count: the number of storage keys to set + * @keys: the byte array where storage keys will be read from + * + * Returns 0 on success, returns an error if setting a storage key fai= led. + */ int (*set_skeys)(S390SKeysState *ks, uint64_t start_gfn, uint64_t coun= t, uint8_t *keys); }; diff --git a/target/s390x/mmu_helper.c b/target/s390x/mmu_helper.c index e2b372efd9..b04b57c235 100644 --- a/target/s390x/mmu_helper.c +++ b/target/s390x/mmu_helper.c @@ -313,6 +313,14 @@ static void mmu_handle_skey(target_ulong addr, int rw,= int *flags) skeyclass =3D S390_SKEYS_GET_CLASS(ss); } =20 + /* + * Don't enable storage keys if they are still disabled, i.e., no actu= al + * storage key instruction was issued yet. + */ + if (!skeyclass->skeys_are_enabled(ss)) { + return; + } + /* * Whenever we create a new TLB entry, we set the storage key reference * bit. In case we allow write accesses, we set the storage key change diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c index 694c0aae63..4fd102ac79 100644 --- a/target/s390x/tcg/mem_helper.c +++ b/target/s390x/tcg/mem_helper.c @@ -2186,6 +2186,9 @@ uint64_t HELPER(iske)(CPUS390XState *env, uint64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); @@ -2213,6 +2216,9 @@ void HELPER(sske)(CPUS390XState *env, uint64_t r1, ui= nt64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 key =3D r1 & 0xfe; @@ -2244,6 +2250,9 @@ uint32_t HELPER(rrbe)(CPUS390XState *env, uint64_t r2) if (unlikely(!ss)) { ss =3D s390_get_skeys_device(); skeyclass =3D S390_SKEYS_GET_CLASS(ss); + if (skeyclass->enable_skeys && !skeyclass->enable_skeys(ss)) { + tlb_flush_all_cpus_synced(env_cpu(env)); + } } =20 rc =3D skeyclass->get_skeys(ss, addr / TARGET_PAGE_SIZE, 1, &key); --=20 2.31.1