From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD345C433DF for ; Thu, 9 Jul 2020 17:55:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6812D20775 for ; Thu, 9 Jul 2020 17:55:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RtgFuio0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6812D20775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtam0-0001Wt-Ov for qemu-devel@archiver.kernel.org; Thu, 09 Jul 2020 13:55:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtalK-0000pC-SH for qemu-devel@nongnu.org; Thu, 09 Jul 2020 13:55:10 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28502 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jtalH-0000da-PR for qemu-devel@nongnu.org; Thu, 09 Jul 2020 13:55:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594317306; 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:autocrypt:autocrypt; bh=kyzbD5sdgYvrskLAHDLEhyyAVOmXcj6Mnh4wlnDt5j8=; b=RtgFuio0v2ImK1xMHTwrw/Z0YFmNix0xh1K0s4tMmSgrwVmYypGuJ3Rmc/6qclHPp/0VjY l2J8OADR8kA7/UevS6lh+h8PuL76JCFAyr60vaG688sCU7dgPvxW67mPQ9kPz2OLLbe0e6 YkFaVmRMnyimMrmICW8Tm9zl0OTXhCU= 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-5-gEn-ypjyP2q02LI00mR-Mw-1; Thu, 09 Jul 2020 13:55:02 -0400 X-MC-Unique: gEn-ypjyP2q02LI00mR-Mw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7858100A8C3; Thu, 9 Jul 2020 17:55:00 +0000 (UTC) Received: from [10.36.112.79] (ovpn-112-79.ams2.redhat.com [10.36.112.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8000D5C662; Thu, 9 Jul 2020 17:54:53 +0000 (UTC) Subject: Re: [PATCH RFC 2/5] s390x: implement diag260 To: Cornelia Huck References: <20200708185135.46694-1-david@redhat.com> <20200708185135.46694-3-david@redhat.com> <20200709123741.28a1e3b2.cohuck@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; prefer-encrypt=mutual; keydata= mQINBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABtCREYXZpZCBIaWxk ZW5icmFuZCA8ZGF2aWRAcmVkaGF0LmNvbT6JAlgEEwEIAEICGwMFCQlmAYAGCwkIBwMCBhUI AgkKCwQWAgMBAh4BAheAFiEEG9nKrXNcTDpGDfzKTd4Q9wD/g1oFAl3pImkCGQEACgkQTd4Q 9wD/g1o+VA//SFvIHUAvul05u6wKv/pIR6aICPdpF9EIgEU448g+7FfDgQwcEny1pbEzAmiw zAXIQ9H0NZh96lcq+yDLtONnXk/bEYWHHU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tFOujp5n+pjBaQK7wUUjDilPQ5QMzIuCL4YjVoylWiBNknvQWBXS lQCWmavOT9sttGQXdPCC5ynI+1ymZC1ORZKANLnRAb0NH/UCzcsstw2TAkFnMEbo9Zu9w7Kv AxBQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAGJAiUEGAECAA8FAlXLn5ECGwwFCQlmAYAACgkQTd4Q 9wD/g1qA6w/+M+ggFv+JdVsz5+ZIc6MSyGUozASX+bmIuPeIecc9UsFRatc91LuJCKMkD9Uv GOcWSeFpLrSGRQ1Z7EMzFVU//qVs6uzhsNk0RYMyS0B6oloW3FpyQ+zOVylFWQCzoyyf227y GW8HnXunJSC+4PtlL2AY4yZjAVAPLK2l6mhgClVXTQ/S7cBoTQKP+jvVJOoYkpnFxWE9pn4t H5QIFk7Ip8TKr5k3fXVWk4lnUi9MTF/5L/mWqdyIO1s7cjharQCstfWCzWrVeVctpVoDfJWp 4LwTuQ5yEM2KcPeElLg5fR7WB2zH97oI6/Ko2DlovmfQqXh9xWozQt0iGy5tWzh6I0JrlcxJ ileZWLccC4XKD1037Hy2FLAjzfoWgwBLA6ULu0exOOdIa58H4PsXtkFPrUF980EEibUp0zFz GotRVekFAceUaRvAj7dh76cToeZkfsjAvBVb4COXuhgX6N4pofgNkW2AtgYu1nUsPAo+NftU CxrhjHtLn4QEBpkbErnXQyMjHpIatlYGutVMS91XTQXYydCh5crMPs7hYVsvnmGHIaB9ZMfB njnuI31KBiLUks+paRkHQlFcgS2N3gkRBzH7xSZ+t7Re3jvXdXEzKBbQ+dC3lpJB0wPnyMcX FOTT3aZT7IgePkt5iC/BKBk3hqKteTnJFeVIT7EC+a6YUFg= Organization: Red Hat GmbH Message-ID: <187bcbd4-a853-ce92-9a26-4aedc585211d@redhat.com> Date: Thu, 9 Jul 2020 19:54:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200709123741.28a1e3b2.cohuck@redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=207.211.31.120; envelope-from=david@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/09 11:02:45 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, 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: Thomas Huth , Janosch Frank , "Michael S . Tsirkin" , Heiko Carstens , qemu-devel@nongnu.org, Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, Claudio Imbrenda , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 09.07.20 12:37, Cornelia Huck wrote: > On Wed, 8 Jul 2020 20:51:32 +0200 > David Hildenbrand wrote: > >> Let's implement the "storage configuration" part of diag260. This diag >> is found under z/VM, to indicate usable chunks of memory tot he guest OS. >> As I don't have access to documentation, I have no clue what the actual >> error cases are, and which other stuff we could eventually query using this >> interface. Somebody with access to documentation should fix this. This >> implementation seems to work with Linux guests just fine. >> >> The Linux kernel supports diag260 to query the available memory since >> v4.20. Older kernels / kvm-unit-tests will later fail to run in such a VM >> (with maxmem being defined and bigger than the memory size, e.g., "-m >> 2G,maxmem=4G"), just as if support for SCLP storage information is not >> implemented. They will fail to detect the actual initial memory size. >> >> This interface allows us to expose the maximum ramsize via sclp >> and the initial ramsize via diag260 - without having to mess with the >> memory increment size and having to align the initial memory size to it. >> >> This is a preparation for memory device support. We'll unlock the >> implementation with a new QEMU machine that supports memory devices. >> >> Signed-off-by: David Hildenbrand >> --- >> target/s390x/diag.c | 57 ++++++++++++++++++++++++++++++++++++++ >> target/s390x/internal.h | 2 ++ >> target/s390x/kvm.c | 11 ++++++++ >> target/s390x/misc_helper.c | 6 ++++ >> target/s390x/translate.c | 4 +++ >> 5 files changed, 80 insertions(+) >> >> diff --git a/target/s390x/diag.c b/target/s390x/diag.c >> index 1a48429564..c3b1e24b2c 100644 >> --- a/target/s390x/diag.c >> +++ b/target/s390x/diag.c >> @@ -23,6 +23,63 @@ >> #include "hw/s390x/pv.h" >> #include "kvm_s390x.h" >> >> +void handle_diag_260(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra) >> +{ >> + MachineState *ms = MACHINE(qdev_get_machine()); >> + const ram_addr_t initial_ram_size = ms->ram_size; >> + const uint64_t subcode = env->regs[r3]; >> + S390CPU *cpu = env_archcpu(env); >> + ram_addr_t addr, length; >> + uint64_t tmp; >> + >> + /* TODO: Unlock with new QEMU machine. */ >> + if (false) { >> + s390_program_interrupt(env, PGM_OPERATION, ra); >> + return; >> + } >> + >> + /* >> + * There also seems to be subcode "0xc", which stores the size of the >> + * first chunk and the total size to r1/r2. It's only used by very old >> + * Linux, so don't implement it. > > FWIW, > https://www-01.ibm.com/servers/resourcelink/svc0302a.nsf/pages/zVMV7R1sc246272/$file/hcpb4_v7r1.pdf > seems to list the available subcodes. Anything but 0xc and 0x10 is for > 24/31 bit only, so we can safely ignore them. Not sure what we want to > do with 0xc: it is supposed to "Return the highest addressable byte of > virtual storage in the host-primary address space, including named > saved systems and saved segments", so returning the end of the address > space should be easy enough, but not very useful. Thanks for the link to the documentation! Either my google search skills are bad or that stuff is just hard to find :) I'll have a look and see how to make sense of 0xc. Smells like "maxram_size - 1" indeed. > >> + */ >> + if ((r1 & 1) || subcode != 0x10) { >> + s390_program_interrupt(env, PGM_SPECIFICATION, ra); >> + return; >> + } >> + addr = env->regs[r1]; >> + length = env->regs[r1 + 1]; >> + >> + /* FIXME: Somebody with documentation should fix this. */ > > Doc mentioned above says for specification exception: > > "For subcode X'10': > • Rx is not an even-numbered register. > • The address contained in Rx is not on a quadword boundary. > • The length contained in Rx+1 is not a positive multiple of 16." > >> + if (!QEMU_IS_ALIGNED(addr, 16) || !QEMU_IS_ALIGNED(length, 16)) { >> + s390_program_interrupt(env, PGM_SPECIFICATION, ra); >> + return; >> + } >> + >> + /* FIXME: Somebody with documentation should fix this. */ >> + if (!length) { > > Probably specification exception as well? Yeah I'll add "|| !length" above. > >> + setcc(cpu, 3); >> + return; >> + } >> + >> + /* FIXME: Somebody with documentation should fix this. */ > > For access exception: > > "For subcode X'10', an error occurred trying to store the extent > information into the guest's output area." > Okay, looks good then! >> + if (!address_space_access_valid(&address_space_memory, addr, length, true, >> + MEMTXATTRS_UNSPECIFIED)) { >> + s390_program_interrupt(env, PGM_ADDRESSING, ra); >> + return; >> + } >> + >> + /* Indicate our initial memory ([0 .. ram_size - 1]) */ >> + tmp = cpu_to_be64(0); >> + cpu_physical_memory_write(addr, &tmp, sizeof(tmp)); >> + tmp = cpu_to_be64(initial_ram_size - 1); >> + cpu_physical_memory_write(addr + sizeof(tmp), &tmp, sizeof(tmp)); >> + >> + /* Exactly one entry was stored. */ >> + env->regs[r3] = 1; >> + setcc(cpu, 0); >> +} >> + >> int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3) >> { >> uint64_t func = env->regs[r1]; > > (...) > >> diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c >> index 58dbc023eb..d7274eb320 100644 >> --- a/target/s390x/misc_helper.c >> +++ b/target/s390x/misc_helper.c >> @@ -116,6 +116,12 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num) >> uint64_t r; >> >> switch (num) { >> + case 0x260: >> + qemu_mutex_lock_iothread(); >> + handle_diag_260(env, r1, r3, GETPC()); >> + qemu_mutex_unlock_iothread(); >> + r = 0; >> + break; >> case 0x500: >> /* KVM hypercall */ >> qemu_mutex_lock_iothread(); > > Looking at the doc referenced above, it seems that we treat every diag > call as privileged under tcg; but it seems that 0x44 isn't? (Unrelated > to your patch; maybe I'm misreading.) Interesting. Adding in onto my todo list. Thanks again! -- Thanks, David / dhildenb