Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp530098rdb; Thu, 15 Feb 2024 07:30:27 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCULP0qIBYHg3hUfZE461rTqK8bRXnjU9YfsdBWG2HJ7+hk0j9OjNssklqKx7Pnse4eGbWlAGbCLIjY5fY2bJQptHRmo8xZwnTFbntKzvg== X-Google-Smtp-Source: AGHT+IE130Kn1RwGANuT0eSaAZUD6XOOZ/AY9G0DSX2L5PuYYzLG4NvLTYjem0AxFkdkkoSKev1z X-Received: by 2002:a17:902:ec8a:b0:1db:28c0:3ec4 with SMTP id x10-20020a170902ec8a00b001db28c03ec4mr3363798plg.7.1708011027723; Thu, 15 Feb 2024 07:30:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708011027; cv=pass; d=google.com; s=arc-20160816; b=F6PPcI3EcNzAKEiDAmJwFW+J63RKfn2WWhYPU9xV2RVg7UiJETMSSqaKfOBgEyujZi Z8ZvBAAi/jrZwX+R1dchyzFB+UrJad4pYbhW7IsHUESQoKptC29MHO13m8Zj0IpI9JFh G1vw0MjGUovEb3vJJt/hHNX8oyJpCNBrAgYv16gWn83qyAsI0qVNPDc4BNEFZiRua/dt IAmaM7zwwxcD/PDRPbbOP3exnLUkfy+JBMQmbwsHJuYT8t9Q0ygdx+8Oz+huakkEU9fJ yRu3VGyx6rYVZVi7CyyPLaasD9I5R6JFhQCSsKB884qUj7E1LxZmZezGiSNOM6hUJu84 f0EA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=5waKWZLX/SeOv5tVvV1GfTPNFSgQingtiL49GthRaLw=; fh=VaF/w+FGpk/prTFLJfCoV+GJDmV0Sd6dt8EMZrBTbz0=; b=mrFzQtPl2V2ta/cXEMw//WjAdv1vFr0OHywy6OmJeQOJmuSAQXQVH9pkoDLlsSV5Da aKnUov/EDY6Dnzk/kzckpwgF9Y9oNjFy6EteNNTWqDJxPEz4m3o62Pq++dVpnzyMbnkS kyaO6Qg4j2Vw4Ih1MWekhkpQG/5zlBfNJHwSkwv6Cq5FfeN71RTJKIjdm9dB8bhKsRJS teAH6sv0ESsugWR5XUsbOnWr0ZapuV6tfhYIBCLU1eqGjhzpjTqpGN+bhlfC8A14/N5O 7NMwUA+YzDtBeoQI/pQRf1+ADhxYksGcZUh1SHTTKK+MfyA4X2CBDk9AsKW0o/EbCRUx OWJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-67110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67110-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f4-20020a170902684400b001d93327867bsi1227528pln.286.2024.02.15.07.30.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 07:30:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-67110-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67110-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C8318B234D3 for ; Thu, 15 Feb 2024 14:56:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60430132494; Thu, 15 Feb 2024 14:56:08 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D32D220B3D; Thu, 15 Feb 2024 14:56:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008967; cv=none; b=e5jSyOTwRfoTCnI/vLEa+MR/2jw3AX+VN+RA12/mOA6IqNgQ17HnXdcUPDIQ+ZDQi6hEcqCZnIM2WVyWJgMmKnKZLp8BbJJ/+CgnKwjqmhznZTGzbePKXx0BHFWzfVmQp0tuH9CvCr5tr1mK0o6T51E+6J/YvFjkmzHWpWfl9I8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708008967; c=relaxed/simple; bh=nH02mRbEf+x2rpYZvYmd3xMiMm7jKKeDp+ZWKf4JDmg=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JvAjG50/LZFPKq5AAPMa6FGRw6i2ZRjarBJ3zHWoN161HMdlhOM9Q/hGP62q9x7cK1eW2/3LHtvU8A3FuijNhUvaBpcabF67fZmKpkXlQ61lGxylUtSuPmEQpxgZtqNJxOW5kMRvyIWCY2K4VLaZdEVda/o4cIzQ1d+Evj2OxqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 853DAC433F1; Thu, 15 Feb 2024 14:56:05 +0000 (UTC) Date: Thu, 15 Feb 2024 09:57:39 -0500 From: Steven Rostedt To: "Masami Hiramatsu (Google)" Cc: Alexei Starovoitov , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v7 20/36] function_graph: Improve push operation for several interrupts Message-ID: <20240215095739.41a2fac7@gandalf.local.home> In-Reply-To: <170723227198.502590.10431025573751489041.stgit@devnote2> References: <170723204881.502590.11906735097521170661.stgit@devnote2> <170723227198.502590.10431025573751489041.stgit@devnote2> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 7 Feb 2024 00:11:12 +0900 "Masami Hiramatsu (Google)" wrote: > From: Masami Hiramatsu (Google) > > Improve push and data reserve operation on the shadow stack for > several sequencial interrupts. > > To push a ret_stack or data entry on the shadow stack, we need to > prepare an index (offset) entry before updating the stack pointer > (curr_ret_stack) so that unwinder from interrupts can find the > next return address from the shadow stack. Currently we do write index, > update the curr_ret_stack, and rewrite it again. But that is not enough > for the case if two interrupts happens and the first one breaks it. > For example, > > 1. write reserved index entry at ret_stack[new_index - 1] and ret addr. > 2. interrupt comes. > 2.1. push new index and ret addr on ret_stack. > 2.2. pop it. (corrupt entries on new_index - 1) > 3. return from interrupt. > 4. update curr_ret_stack = new_index > 5. interrupt comes again. > 5.1. unwind <------ may not work. I'm curious if you saw this happen? That is, did you trigger this or only noticed it by inspection? This code is already quite complex, I would like to simplify it more before we try to fix rare race conditions that only affect the unwinder. Let's hold off on this change. -- Steve > > To avoid this issue, this introduces a new rsrv_ret_stack stack > reservation pointer and a new push code (slow path) to commit > previous reserved code forcibly. > > 0. update rsrv_ret_stack = new_index. > 1. write reserved index entry at ret_stack[new_index - 1] and ret addr. > 2. interrupt comes. > 2.0. if rsrv_ret_stack != curr_ret_stack, add reserved index > entry on ret_stack[rsrv_ret_stack - 1] to point the previous > ret_stack pointed by ret_stack[curr_ret_stack - 1]. and > update curr_ret_stack = rsrv_ret_stack. > 2.1. push new index and ret addr on ret_stack. > 2.2. pop it. (corrupt entries on new_index - 1) > 3. return from interrupt. > 4. update curr_ret_stack = new_index > 5. interrupt comes again. > 5.1. unwind works, because curr_ret_stack points the previously > saved ret_stack. > 5.2. this can do push/pop operations too. > 6. return from interrupt. > 7. rewrite reserved index entry at ret_stack[new_index] again. > > This maybe a bit heavier but safer. > > Signed-off-by: Masami Hiramatsu (Google)