From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 997953849AF5 for ; Wed, 8 May 2024 16:09:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 997953849AF5 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 997953849AF5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715184600; cv=none; b=p5iMmIwuzYiXd8V+DoWUSdYxXyyX3HYi3NFWaot+T4Cou0WB2GvmQXGeea2yo+Z+FDDacu0hxtHjWGk6apuyQ9VsfCeCOgWQG1U+zsysGaiL1UrqBgiCr2+czCye07Hwy+Jf4zYbgrBFBVbmZe8+y6UmlmLp2Mov0hccTB6cZ6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715184600; c=relaxed/simple; bh=rLPmZNsWvgnVlY/qCiTryRjrmZdD1vjxqXJq5XKH1mM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k699rm7mp92jt9mYIrOylUPML/tvNBgi0JMPg5zcsQuMZEib/1xA6FiAPOLoMuUQYur3eiFNWuUMqHk2yPGrxEVdSAzEq7oyL5aDIn0NkG10RxP673iY4IbIi/UmYgBx3YzxZHWx84BNUe5qInm5tb3H/6HMbIi095coUw7GcCA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715184596; 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: in-reply-to:in-reply-to:references:references; bh=mOAAC6uwvnw96cW2F/7kzd6LEdSLc8eP4N0v5bXr1VM=; b=FYsGn6SaOm1p9FYRDS4Tr69DgNFSVLkzoMW/IInO3m/qwDtoZIwGW15UYw/IMe9Az9KhtG RHeIF8W114E7wV6vcIwuNA464BIIFo6jL7JQPQmxookZodT4fjr4ZWRG/jFvCHu60UqRHe TdASDuGn/Vq6CN7PVWyay2YRzbf6mqc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-JKvpoz4iO1eHvBwetXtr9A-1; Wed, 08 May 2024 12:09:37 -0400 X-MC-Unique: JKvpoz4iO1eHvBwetXtr9A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-41dc9c831acso5214315e9.0 for ; Wed, 08 May 2024 09:09:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715184571; x=1715789371; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mOAAC6uwvnw96cW2F/7kzd6LEdSLc8eP4N0v5bXr1VM=; b=kP/5ORewH7YFGCk+bIECO9Z6zyboa/sPg5W4FlIGrK1p14uPWsL2BsH7Z9YLKZD05b xhCKVs39MnuDpwisVX9NLfR4Hn//mMEm+4lMutkz2/CH2MR8bn5NCdLpRKTM+MIMoPTJ spTpRw+oetQ+4sU+xJ9VtQ/EJbAxhLWjS3eyB5dCvyEOiAbtMLitSRvUk4Y/GEj4xBgf i2qwqUXho1SITswSIkp76YESbftVGxk1JrrT9/AEKcsNkBwgSNrEXnW1fATURPUzx4Sj AnuYZzCvBl/ZB02+V5C7IpF8XOwhC4PsqLRF7BqRcNnW8vW21J0U1MS11mGPv0SwlQ7c /n5g== X-Forwarded-Encrypted: i=1; AJvYcCUzF2O7puZa7+6uRzIHB7yr4ejv2O9fxjPDF/gPGMo0P4fAsmxm/eJ9fDlp+B7K3YlFiSuv4vhMXalgbIAwDKTTgOyG98LdtFSZcw== X-Gm-Message-State: AOJu0YxDrR6N9iVXIKfeMQPa3XK3HywEk+AonAQygVEcQ6XsMz36vAT7 oknAyL2lD+6M3NNJ2NvOZVbgJhikxJYWCPzTrsb1guMUnrEBOteDzdMmlxKKXj6Bc7wMwkznW7N FkGqWHKb3rf8v1hp9JP0vTSV2CnN2ns6ac5D8+URq1AXyoYnkQ/dzebPvLTRdvP+XPC4= X-Received: by 2002:a05:600c:4f82:b0:41a:7c1d:3326 with SMTP id 5b1f17b1804b1-41fbcb4b251mr922035e9.8.1715184570873; Wed, 08 May 2024 09:09:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVoD1djA0B0+2PjczqXu4KtqOsS9HtLkddCg0ia6Hejbxh6DZJIRSmSvQEJEHJCQHnU6/vdg== X-Received: by 2002:a05:600c:4f82:b0:41a:7c1d:3326 with SMTP id 5b1f17b1804b1-41fbcb4b251mr921755e9.8.1715184570187; Wed, 08 May 2024 09:09:30 -0700 (PDT) Received: from localhost ([31.111.84.240]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f87b2653bsm28008095e9.4.2024.05.08.09.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 09:09:29 -0700 (PDT) From: Andrew Burgess To: "Willgerodt, Felix" , "gdb-patches@sourceware.org" Cc: John Baldwin Subject: RE: [PATCHv5 11/11] gdb/gdbserver: share x86/linux tdesc caching In-Reply-To: References: <87pltxu14z.fsf@redhat.com> Date: Wed, 08 May 2024 17:09:28 +0100 Message-ID: <87seyss2tj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: "Willgerodt, Felix" writes: >> >> diff --git a/gdb/arch/amd64-linux-tdesc.c b/gdb/arch/amd64-linux-tdesc.c >> >> new file mode 100644 >> >> index 00000000000..63b5ddfcece >> >> --- /dev/null >> >> +++ b/gdb/arch/amd64-linux-tdesc.c >> >> @@ -0,0 +1,61 @@ >> >> +/* Target description related code for GNU/Linux x86-64. >> >> + >> >> + Copyright (C) 2024 Free Software Foundation, Inc. >> >> + >> >> + This file is part of GDB. >> >> + >> >> + This program is free software; you can redistribute it and/or modify >> >> + it under the terms of the GNU General Public License as published by >> >> + the Free Software Foundation; either version 3 of the License, or >> >> + (at your option) any later version. >> >> + >> >> + This program is distributed in the hope that it will be useful, >> >> + but WITHOUT ANY WARRANTY; without even the implied warranty of >> >> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >> >> + GNU General Public License for more details. >> >> + >> >> + You should have received a copy of the GNU General Public License >> >> + along with this program. If not, see . */ >> >> + >> >> +#include "arch/x86-linux-tdesc.h" >> >> +#include "arch/amd64-linux-tdesc.h" >> >> +#include "arch/amd64.h" >> >> +#include "arch/x86-linux-tdesc-features.h" >> >> + >> >> + >> >> +/* See arch/amd64-linux-tdesc.h. */ >> >> + >> >> +const struct target_desc * >> >> +amd64_linux_read_description (uint64_t xcr0, bool is_x32) >> >> +{ >> >> + /* The type used for the amd64 and x32 target description caches. */ >> >> + using tdesc_cache_type = std::unordered_map> >> target_desc_up>; >> >> + >> >> + /* Caches for the previously seen amd64 and x32 target descriptions, >> >> + indexed by the xcr0 value that created the target description. These >> >> + need to be static within this function to ensure they are initialised >> >> + before first use. */ >> >> + static tdesc_cache_type amd64_tdesc_cache, x32_tdesc_cache; >> >> + >> > >> > Sorry for this long comment, it isn't strictly related to your series, as you don't >> > change the status quo. But since you are changing the cache, I find it relevant. >> > >> > I wonder if caching of target descriptions based on xcr0 alone is really >> > good enough. It isn't always the only thing used for determining registers. >> > I realize you don't change that fact, though with the map we would need to >> > hash xcr0 with the other factors for the key. Arguably that could still be >> > viewed as better than the current way. >> > >> > Right now there is already the segments and "orig_rax" register for amd64. >> > Though I don't know if IPA really supports them and I am not super familiar with >> > their details. It seems like we just add them unconditionally or based on >> whether >> > or not we are on Linux. I am not really sure that means we don't care about >> them >> > for our cache (especially the Linux part), but it seems that is the current state. >> > >> > But in the near future there will be the shadow stack pointer register for CET, >> > which we can only read with a separate ptrace call. >> > See this patch, which we want to post soon: >> > >> https://github.com/intel/gdb/commit/afff428f38a1f03ac0127797deda524d81ec1 >> 56e >> > >> > I must admit I never really fully understood why this caching is done. >> > Is it for a single GDB session connecting to different gdbserver sessions one >> > after the other? Or for inferior re-starts? >> > Or for runtime target description updates similar to SVE on aarch64? >> > (Which we will also add at some point for AMX on x86.) >> > Or a mix of all? >> >> You are 100% correct. And I agree with everything you've said. >> >> I also spotted this issue and had a choice to make. >> >> I could: >> >> (a) fix the caching mechanism first, which would require duplicating >> the effort in GDB and gdbserver, then >> >> (b) merge the GDB and gdbserver code. >> >> Or I could: >> >> (a) merge the GDB and gdbserver code, then >> >> (b) fix the caching mechanism. >> >> As you can see, I opted to merge the code first, but this was already 11 >> patches. Which is going to be at least 12 in v6. >> >> Realistically, if I tried to "fix" caching at the same time then either >> each patch is going to get much bigger (and break the one change per >> patch rule) or the series is going to start getting really long. >> >> I've stopped where I have to try and keep the number of patches down; I >> don't want to overload reviewers. Plus, if I write too much on top of >> earlier patches and get asked to rewrite things the rewrites become more >> work. > > I agree that we need to take this step by step and try to keep this series > focused on the actual goal. For your sake and the sake of reviewers. > >> My plan after this series is merged was to unify all of the x86 tdesc >> caching, not just for Linux, but for all x86 targets (e.g. FreeBSD). I >> was going to adopt an approach similar to the approach I used for >> risc-v, which I think works pretty well, that is have a single struct >> that can holds all the features that impact tdesc creation, give that >> struct a hash() function, and then use this as the key for caching >> created tdesc. >> >> I'll take a look and see if I can do something part way towards this >> solution as part of this patch which would address your immediate >> concerns. > > Thanks a lot, I wasn't aware that risc-v already has a solution for this. > > Just for the record, I also would find it ok to not change to a > map for this series yet. Though I for sure won't object to doing it > here either. I'd like to update my response to your feedback a little. You originally asked: > I wonder if caching of target descriptions based on xcr0 alone is really > good enough. It isn't always the only thing used for determining registers. > I realize you don't change that fact, though with the map we would need to > hash xcr0 with the other factors for the key. Arguably that could still be > viewed as better than the current way. And don't think I was clear enough in my reply. As far as this patch is concerned, caching based only on xcr0 is absolutely fine. Remember that this series is only for Linux, and for Linux the other (non xcr0) flags that are used when creating a target description (the is_linux and segments arguments to {amd64,i386}_create_target_description) are always given fixed values. As such we don't need to consider these flags at all when caching target descriptions (for x86 Linux). Once this series is merged, as I've said, I'd like to look at extending the caching to all x86 targets, in which case we will need to consider all the flags. The reason that I switched from an array to a map in this commit is because I wanted to avoid hard coding the array sizes for each x86 target type (i386, amd64, x32): - Only in gdb/arch/x86-linux-tdesc-features.c could we make use of the constexpr x86_linux_*_tdesc_count_1() functions to create fixed C-style arrays of the required sizes, this would require all of the caching code to live in this file, which didn't seem right, - I could move to a dynamic array like structure, e.g. std::vector, I could then grow the cache as needed, but I figure if I'm going to change the data structure anyway, then I might as well go with a map, - So I switched to use a map structure, keyed off the xcr0, which is fine, because (for x86 Linux) that's the only value that matters. I'll update the commit message to try and explain all this a bit better. Thanks, Andrew