From patchwork Tue Feb 6 21:10:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6305C48297 for ; Tue, 6 Feb 2024 22:12:46 +0000 (UTC) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mx.groups.io with SMTP id smtpd.web10.4832.1707253879073683986 for ; Tue, 06 Feb 2024 13:11:19 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=emUWwE4r; spf=pass (domain: gmail.com, ip: 209.85.214.177, mailfrom: schmitzmic@gmail.com) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d7881b1843so54910135ad.3 for ; Tue, 06 Feb 2024 13:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253878; x=1707858678; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=I2CG33VPPpXBW0bT6gJ7H7D26BUksG/NvgMt6SM3LZM=; b=emUWwE4rG8Ftdg74cqpsULthWdnyBvAnYE6tFZTMQHNJUdqYuMWoMzGwQzLZM0hH12 JPN7k667HNPlmratxntaWqo5BfxXUIFBwgYcjGESUO1FBbLntOYqSCZU6qQU+pqKgyGo 3Y2Rk/PJV3G7HDtZ86jNmd9JuGjns1qDxIwBgLxD994jjbNFQV1dPKzSUcIsXqTVb1X1 XKHMmOEFz2G464Jc9O/8hfBlCa/06qVI3VzAeIaqih5vM3ljGlWWFEP7MYpKocXzT4aK s2wKdiT83pJDDvcTeY+Kj17L523JPNTJUvBy3lidIygsYkmMNdfkz6yfCWkFTqy+9sP9 BX7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253878; x=1707858678; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I2CG33VPPpXBW0bT6gJ7H7D26BUksG/NvgMt6SM3LZM=; b=m5MyP5aVq54n/G7h/5qHdjUOo+97aKG6gMF99w/ryZIm1HpaGOBxbH9V2dYnZPLhQP B2NRvrTi4W3Kt3cDkzxjk/Hn0lsGOjHJ9mMuss0DvvKt8ntnS6WRz1yCEing9zdSWor+ /2lENTpX+g3fmSfZktCruY8W1X75DVfi2lgZ6bH1/hvhpDVxSqj3+MTJP8QUbLv7Gp6q lvRDzAzdyn5kZkyKUe6AXIK7r6ZY5Z2kUm6Cn2/k7UEet1C0IL7kXeumNH2Rp5/2LpNV 3Lyzpmz73D28Q1NUqC4Dynx+Gq/cKEPcGGd0HMsurthFERCwv298AHDVSJVaBOXsoo0L jjcA== X-Gm-Message-State: AOJu0Yy0xtaUNV1NEb+OjWcgKckdmV9m24yAzhwgVXWWdu0zzpvmFyY7 48xCvp8KflocAWJVlgDUU/6uBv7kuBjl8qsn5M6+1NOhK5yGV48K X-Google-Smtp-Source: AGHT+IGVeb5RZpfylDVMc7uFzF0bFVYLKe4HdkLjmpP7649rzmcsyMIf+ArF8LarY9xNjUUvum2wXQ== X-Received: by 2002:a17:90b:1bc2:b0:296:a746:67f5 with SMTP id oa2-20020a17090b1bc200b00296a74667f5mr713716pjb.44.1707253878470; Tue, 06 Feb 2024 13:11:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW5VIR9m9MMf8pmz/Juke+rIkiaThYJzHJEqOC6aLZ9e2M+FwS4sPB2eyROhKpqeAHdIkbPQy2JINmb71r9IAgdX4igZZDAs3slsD2qWziJjP51PAEccx8LWS+M1b2XHsOAQW8nETQFLTVwyfZMKjNLdGW+H0GH+lVta8YAKMl8wyRejRxG5qCyXKC1LrSmpMtYgEZQW89ZewsAwjsJPJbWycuIzCPX40cyUwyZW1iWp8JE37FBsk/fcw== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id z6-20020a17090a468600b002961ccd55e4sm2143578pjf.31.2024.02.06.13.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:17 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id B2A2036031F; Wed, 7 Feb 2024 10:11:13 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, Michael Schmitz , stable@vger.kernel.org, cip-dev@lists.cip-project.org Subject: [PATCH v3 1/8] m68k/mm: Adjust VM area to be unmapped by gap size for __iounmap() Date: Wed, 7 Feb 2024 10:10:57 +1300 Message-Id: <20240206211104.26421-2-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:12:46 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14834 commit 3f90f9ef2dda316d64e420d5d51ba369587ccc55 upstream. If 020/030 support is enabled, get_io_area() leaves an IO_SIZE gap between mappings which is added to the vm_struct representing the mapping. __ioremap() uses the actual requested size (after alignment), while __iounmap() is passed the size from the vm_struct. On 020/030, early termination descriptors are used to set up mappings of extent 'size', which are validated on unmapping. The unmapped gap of size IO_SIZE defeats the sanity check of the pmd tables, causing __iounmap() to loop forever on 030. On 040/060, unmapping of page table entries does not check for a valid mapping, so the umapping loop always completes there. Adjust size to be unmapped by the gap that had been added in the vm_struct prior. This fixes the hang in atari_platform_init() reported a long time ago, and a similar one reported by Finn recently (addressed by removing ioremap() use from the SWIM driver. Tested on my Falcon in 030 mode - untested but should work the same on 040/060 (the extra page tables cleared there would never have been set up anyway). Signed-off-by: Michael Schmitz [geert: Minor commit description improvements] [geert: This was fixed in 2.4.23, but not in 2.5.x] Signed-off-by: Geert Uytterhoeven Cc: stable@vger.kernel.org Cc: # 4.4 --- arch/m68k/mm/kmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/m68k/mm/kmap.c b/arch/m68k/mm/kmap.c index 6e4955bc542b..fcd52cefee29 100644 --- a/arch/m68k/mm/kmap.c +++ b/arch/m68k/mm/kmap.c @@ -88,7 +88,8 @@ static inline void free_io_area(void *addr) for (p = &iolist ; (tmp = *p) ; p = &tmp->next) { if (tmp->addr == addr) { *p = tmp->next; - __iounmap(tmp->addr, tmp->size); + /* remove gap added in get_io_area() */ + __iounmap(tmp->addr, tmp->size - IO_SIZE); kfree(tmp); return; } From patchwork Tue Feb 6 21:10:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547858 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6A71C48297 for ; Tue, 6 Feb 2024 22:12:56 +0000 (UTC) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mx.groups.io with SMTP id smtpd.web10.4834.1707253886408310373 for ; Tue, 06 Feb 2024 13:11:26 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=XtfdMm8j; spf=pass (domain: gmail.com, ip: 209.85.214.173, mailfrom: schmitzmic@gmail.com) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d8aadc624dso46277145ad.0 for ; Tue, 06 Feb 2024 13:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253886; x=1707858686; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=PqE6uH8/Cq6TCWIinemSe0QCaBK2NUC2RCn1iBCFHF4=; b=XtfdMm8jUV2loBBkR5gks1ekIZAjyuryzLzTjCSLXoHvrD/jAMVUvbQntxHdqDqE2w gJYkN68m/aZY6GJ0D901Pu6pzfmipBZxAfae/pcB5FfP2rpRHtpbAuabXle30xCZAfwF /E6VSzuguMoNPG90w2rJ85Wh080N6lKNrWcmArgYurGUmFXZCLKnOMWmZM2YWhWVMRC5 EiTvplvNl6eeqTt2Ta1dEO4YTUFnY72YRnTPwLaKoZEwMU9b4H/9s46YPrRI+KUOvZ/O Sp0Bhn+NtLO1+yXl+2l7EwOH+E8DVY7eJag0/6vlMeDLisru700hK1h1eRQdE31rrAFU DMGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253886; x=1707858686; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PqE6uH8/Cq6TCWIinemSe0QCaBK2NUC2RCn1iBCFHF4=; b=OBMInyNU0EzpmUTVcoRcmUNDeekYWlkV1WSY3FbPHowXCNcgATKHZwZIcoDi84wWqV ImCxaqvP4iw5iBYtUYWboeEFWRTYCVdl83VzEodTKztmJDFfc4AV+rECzCSsMEqaYhG7 EGj9I7AaoSeCzTIa9kKBK3toH1VegrcjCd1mYXQN3schTmfHh3keKjxyGc6QQ8Acrh+V JiDeWz6UBOZxtDagjGJcncrP5M5q11sh2a33gy/c51esadokCIvwQBiLdwc95JMq9+tS rv9oV2C0Vj+hlXxIF9JpC/gnxo3SPhTySMOv5cGsbLSzD8lyQdtrdDR5t9X2Z/pkCAcY tKJg== X-Gm-Message-State: AOJu0YytwLVXAn7ab0P8VyiX/40RRwWIzfU2CGvDXn+1hObS6wxmUzHQ BpPgFDXuRqccNKn0q9+PRZ+q0JdsUi4qdWzITXn3Dyb3buSIrcXS X-Google-Smtp-Source: AGHT+IGmwQSPPVAt+TE0g2WV2ikuAiWW1r5pv64s3VnqEsrnUBfJD2yzCMTBgUZsPlSokFKOt089Fg== X-Received: by 2002:a17:903:2288:b0:1d9:a50f:90eb with SMTP id b8-20020a170903228800b001d9a50f90ebmr2527928plh.38.1707253884921; Tue, 06 Feb 2024 13:11:24 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVhe+1o7MZf0ZSLPDZ89G3eyIBq8NltOXhakk3m26xDrJwW4qI7QoVVnk8nsn8yXic0ptWCm4BtqEEpC63k7SXFYDWL0F7v6CpArw4roTs9lTrQ3VClGvkvr+sgbx23CMJ6S1K9xzafRTONIiq3PSrR3BtkPS9nEja//QnuY5ccxgszJXjtVlPsRVz7omfIXAElZLt8r/xgRSwb4gzb7BCSvA== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id kv4-20020a17090328c400b001d9df9589e5sm1661523plb.10.2024.02.06.13.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:24 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 4072136031F; Wed, 7 Feb 2024 10:11:21 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, Michael Schmitz , cip-dev@lists.cip-project.org Subject: [PATCH v3 3/8] m68k: include module.h to make use of exception handling in traps.c Date: Wed, 7 Feb 2024 10:10:59 +1300 Message-Id: <20240206211104.26421-4-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:12:56 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14835 Backporting commit 513138a14063760e (m68k: Only force 030 bus error if PC not in exception table) to v4.4 by the CIP project revealed a build error due to extable.h not yet available. extable.h was split off module.h in v4.8 (commit 0ef7653797addea8) so amend 513138a14063760e accordingly. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202401302324.d3o6tgup-lkp@intel.com/ Cc: # 4.4 Cc: Ulrich Hecht Cc: Geert Uytterhoeven Signed-off-by: Michael Schmitz --- arch/m68k/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/m68k/kernel/traps.c b/arch/m68k/kernel/traps.c index c547140b8325..2209214cf91c 100644 --- a/arch/m68k/kernel/traps.c +++ b/arch/m68k/kernel/traps.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include From patchwork Tue Feb 6 21:11:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9A48C4829A for ; Tue, 6 Feb 2024 22:12:56 +0000 (UTC) Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by mx.groups.io with SMTP id smtpd.web10.4835.1707253886634051728 for ; Tue, 06 Feb 2024 13:11:26 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OXTrcr1R; spf=pass (domain: gmail.com, ip: 209.85.210.169, mailfrom: schmitzmic@gmail.com) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e065abd351so41166b3a.3 for ; Tue, 06 Feb 2024 13:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253886; x=1707858686; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=zkqg+eFzaY2S/u8Ml2dXeOowbMrMt0zE1hQJncnSBIw=; b=OXTrcr1RLDF+gL32A/Fs339XG4sKXccpixRSLqC/vvI+8YzqPXpI9zRrqw5ydnzimn eakN8kDd4ttSiA2ASzK+1A2Vf2/d4/A/WfOY5KIAt6IBYvBO5yRKq85dM+iu7x1WvfM4 4JLD63rl9gGcahBttmFeShUrj0WyThLAcTgGkyS2FFIMSyZao7h3gNJxQXl9GAO57YP0 P9MEEzB5bGhpGMmLKVLn19L4/YXNpeWk0sABrJken1/YLxDD9xchsFMdj6Pi3rynC07n EGoGUPTB2AjRPFBUm0f6spwoRq1yoHrs0KQR5JuiWqq5gjPNZxV5UXCZzNBtmqifXLY4 bYOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253886; x=1707858686; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zkqg+eFzaY2S/u8Ml2dXeOowbMrMt0zE1hQJncnSBIw=; b=beVkUjV82SxuRHY3t3guG7g6XRrmwdGtcKEUorKl9T9YzbO6mv493Qrisox5K8VDhQ SZIlmLFi8L5rm5+blkTdIM25biV6b3BfuvXkKSEFen/Xwl+tCtrZGR0EUeyAJKHxdFEO LccpuWMQo2aqcDAswgewxLgff1seKk4zQ+vI1V1DMX6/PYtvnjCi5qzElaBF4kFwnSF3 tXEwf+LUkwsuG9mi5EftMS7pgF8VmqE8U1HFSZkbP6aH973GZ+c4MnaRpzi9BIwBDC5a w+Oyg6LQMmoZThOQ+ggQM014ARdo3tLJZpqZhybPO0WRISZhIrAIFuQLAcEyY6XIOkJi htoA== X-Gm-Message-State: AOJu0YxNdIdn99VDMLiC4VBJBKKhX7oOgz0b8/p3S/FcQoWvmWYH6uG6 WPRnRDPG/3LUP3uDkTEMwu5ebfx8loDTKQ5rA1zxHzvUzyngPI57 X-Google-Smtp-Source: AGHT+IHVQ6lQbWQxawf9YzN908IdwFWfGcgu1QyaGqWhcZZ+hyKQ3AhUppBt4m1p5n9wNO92InqghA== X-Received: by 2002:a05:6a20:9687:b0:19e:3af0:af33 with SMTP id hp7-20020a056a20968700b0019e3af0af33mr2705294pzc.60.1707253886059; Tue, 06 Feb 2024 13:11:26 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU/gWOh6hWcEOWt/LTJnuUAkv84xiNF15vuAuNc/rWcB6ssZo5cnk4AXBZlL9ldX3sAQwkDX0aJoO5DxHWva+VaByxiFMnH9soE95IAiWNW/iRCoXV/5Mvx6RxKK91zKyDx+p/jCsvSljMcnWKf5bJg6g+K/C2ppajYV7DdJiBtAsPXxggI3zp8PvG1hlH1Czgb33h4lTBOVCgsxixW0SWzjQ== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id x15-20020aa79a4f000000b006ddc133f1d3sm2411449pfj.194.2024.02.06.13.11.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:25 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 1DC8C36032D; Wed, 7 Feb 2024 10:11:22 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, cip-dev@lists.cip-project.org, Michael Schmitz Subject: [PATCH v3 4/8] m68k: Handle arrivals of multiple signals correctly Date: Wed, 7 Feb 2024 10:11:00 +1300 Message-Id: <20240206211104.26421-5-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:12:56 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14836 From: Al Viro commit 4bb0bd81ce5e97092dfda6a106d414b703ec0ee8 upstream. When we have several pending signals, have entered with the kernel with large exception frame *and* have already built at least one sigframe, regs->stkadj is going to be non-zero and regs->format/sr/pc are going to be junk - the real values are in shifted exception stack frame we'd built when putting together the first sigframe. If that happens, subsequent sigframes are going to be garbage. Not hard to fix - just need to find the "adjusted" frame first and look for format/vector/sr/pc in it. Signed-off-by: Al Viro Tested-by: Michael Schmitz Reviewed-by: Michael Schmitz Tested-by: Finn Thain Link: https://lore.kernel.org/r/YP2dBIAPTaVvHiZ6@zeniv-ca.linux.org.uk Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202401310920.sBSI4BHj-lkp@intel.com/ Signed-off-by: Geert Uytterhoeven [MSch: Minor v4.4 backport merge conflict fixes] Cc: # 4.4 Signed-off-by: Michael Schmitz --- arch/m68k/kernel/signal.c | 100 +++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 55 deletions(-) diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c index af1c4f330aef..644c2ddc8aac 100644 --- a/arch/m68k/kernel/signal.c +++ b/arch/m68k/kernel/signal.c @@ -465,7 +465,7 @@ static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs) if (CPU_IS_060 ? sc->sc_fpstate[2] : sc->sc_fpstate[0]) { fpu_version = sc->sc_fpstate[0]; - if (CPU_IS_020_OR_030 && + if (CPU_IS_020_OR_030 && !regs->stkadj && regs->vector >= (VEC_FPBRUC * 4) && regs->vector <= (VEC_FPNAN * 4)) { /* Clear pending exception in 68882 idle frame */ @@ -528,7 +528,7 @@ static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs * if (!(CPU_IS_060 || CPU_IS_COLDFIRE)) context_size = fpstate[1]; fpu_version = fpstate[0]; - if (CPU_IS_020_OR_030 && + if (CPU_IS_020_OR_030 && !regs->stkadj && regs->vector >= (VEC_FPBRUC * 4) && regs->vector <= (VEC_FPNAN * 4)) { /* Clear pending exception in 68882 idle frame */ @@ -788,18 +788,24 @@ badframe: return 0; } +static inline struct pt_regs *rte_regs(struct pt_regs *regs) +{ + return (void *)regs + regs->stkadj; +} + static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, unsigned long mask) { + struct pt_regs *tregs = rte_regs(regs); sc->sc_mask = mask; sc->sc_usp = rdusp(); sc->sc_d0 = regs->d0; sc->sc_d1 = regs->d1; sc->sc_a0 = regs->a0; sc->sc_a1 = regs->a1; - sc->sc_sr = regs->sr; - sc->sc_pc = regs->pc; - sc->sc_formatvec = regs->format << 12 | regs->vector; + sc->sc_sr = tregs->sr; + sc->sc_pc = tregs->pc; + sc->sc_formatvec = tregs->format << 12 | tregs->vector; save_a5_state(sc, regs); save_fpu_state(sc, regs); } @@ -807,6 +813,7 @@ static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs *regs) { struct switch_stack *sw = (struct switch_stack *)regs - 1; + struct pt_regs *tregs = rte_regs(regs); greg_t __user *gregs = uc->uc_mcontext.gregs; int err = 0; @@ -827,9 +834,9 @@ static inline int rt_setup_ucontext(struct ucontext __user *uc, struct pt_regs * err |= __put_user(sw->a5, &gregs[13]); err |= __put_user(sw->a6, &gregs[14]); err |= __put_user(rdusp(), &gregs[15]); - err |= __put_user(regs->pc, &gregs[16]); - err |= __put_user(regs->sr, &gregs[17]); - err |= __put_user((regs->format << 12) | regs->vector, &uc->uc_formatvec); + err |= __put_user(tregs->pc, &gregs[16]); + err |= __put_user(tregs->sr, &gregs[17]); + err |= __put_user((tregs->format << 12) | tregs->vector, &uc->uc_formatvec); err |= rt_save_fpu_state(uc, regs); return err; } @@ -846,15 +853,14 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) { struct sigframe __user *frame; - int fsize = frame_extra_sizes(regs->format); + struct pt_regs *tregs = rte_regs(regs); + int fsize = frame_extra_sizes(tregs->format); struct sigcontext context; int err = 0, sig = ksig->sig; if (fsize < 0) { -#ifdef DEBUG - printk ("setup_frame: Unknown frame format %#x\n", - regs->format); -#endif + pr_debug("setup_frame: Unknown frame format %#x\n", + tregs->format); return -EFAULT; } @@ -865,7 +871,7 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, err |= __put_user(sig, &frame->sig); - err |= __put_user(regs->vector, &frame->code); + err |= __put_user(tregs->vector, &frame->code); err |= __put_user(&frame->sc, &frame->psc); if (_NSIG_WORDS > 1) @@ -890,36 +896,28 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set, push_cache ((unsigned long) &frame->retcode); - /* - * Set up registers for signal handler. All the state we are about - * to destroy is successfully copied to sigframe. - */ - wrusp ((unsigned long) frame); - regs->pc = (unsigned long) ksig->ka.sa.sa_handler; - adjustformat(regs); - /* * This is subtle; if we build more than one sigframe, all but the * first one will see frame format 0 and have fsize == 0, so we won't * screw stkadj. */ - if (fsize) + if (fsize) { regs->stkadj = fsize; - - /* Prepare to skip over the extra stuff in the exception frame. */ - if (regs->stkadj) { - struct pt_regs *tregs = - (struct pt_regs *)((ulong)regs + regs->stkadj); -#ifdef DEBUG - printk("Performing stackadjust=%04x\n", regs->stkadj); -#endif - /* This must be copied with decreasing addresses to - handle overlaps. */ + tregs = rte_regs(regs); + pr_debug("Performing stackadjust=%04lx\n", regs->stkadj); tregs->vector = 0; tregs->format = 0; - tregs->pc = regs->pc; tregs->sr = regs->sr; } + + /* + * Set up registers for signal handler. All the state we are about + * to destroy is successfully copied to sigframe. + */ + wrusp ((unsigned long) frame); + tregs->pc = (unsigned long) ksig->ka.sa.sa_handler; + adjustformat(regs); + return 0; } @@ -927,7 +925,8 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs) { struct rt_sigframe __user *frame; - int fsize = frame_extra_sizes(regs->format); + struct pt_regs *tregs = rte_regs(regs); + int fsize = frame_extra_sizes(tregs->format); int err = 0, sig = ksig->sig; if (fsize < 0) { @@ -978,36 +977,27 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, push_cache ((unsigned long) &frame->retcode); - /* - * Set up registers for signal handler. All the state we are about - * to destroy is successfully copied to sigframe. - */ - wrusp ((unsigned long) frame); - regs->pc = (unsigned long) ksig->ka.sa.sa_handler; - adjustformat(regs); - /* * This is subtle; if we build more than one sigframe, all but the * first one will see frame format 0 and have fsize == 0, so we won't * screw stkadj. */ - if (fsize) + if (fsize) { regs->stkadj = fsize; - - /* Prepare to skip over the extra stuff in the exception frame. */ - if (regs->stkadj) { - struct pt_regs *tregs = - (struct pt_regs *)((ulong)regs + regs->stkadj); -#ifdef DEBUG - printk("Performing stackadjust=%04x\n", regs->stkadj); -#endif - /* This must be copied with decreasing addresses to - handle overlaps. */ + tregs = rte_regs(regs); + pr_debug("Performing stackadjust=%04lx\n", regs->stkadj); tregs->vector = 0; tregs->format = 0; - tregs->pc = regs->pc; tregs->sr = regs->sr; } + + /* + * Set up registers for signal handler. All the state we are about + * to destroy is successfully copied to sigframe. + */ + wrusp ((unsigned long) frame); + tregs->pc = (unsigned long) ksig->ka.sa.sa_handler; + adjustformat(regs); return 0; } From patchwork Tue Feb 6 21:11:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D65A9C4829A for ; Tue, 6 Feb 2024 22:13:06 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by mx.groups.io with SMTP id smtpd.web11.4721.1707253888541034001 for ; Tue, 06 Feb 2024 13:11:28 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FjrcPNQo; spf=pass (domain: gmail.com, ip: 209.85.215.177, mailfrom: schmitzmic@gmail.com) Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5d3907ff128so5309568a12.3 for ; Tue, 06 Feb 2024 13:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253888; x=1707858688; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=dGqIsAq8M3OyZBp1sy4dZz2sGDg3iZRmY3s8GmeRm7w=; b=FjrcPNQoz1ij1Dj0NynUg09d2pJ0TCvWxs1REpCHi2u94VN4uT39fsa7AoR6+gBm3y 24/101uTDRcCqU4FDYPqSSBxOJ7d1nRbY6owKzrP94m72RwBDqXw6lXfIFqlHuv42GRh 6H0UOLdpulwMk3OJSnSwBZhTkEge0PP0PfNP8qzzk8uYqAj0cn3HXEDX5sqC/43oMPEb r0AK4L7XLlFY59czFW6g8DKvQsu9W+TrT0cR9+i1Zelu5DpqRF2pZpQ93EujS/vBTRKd Hg/n6l7thxZXYt+H7MT8M6d2E4e2bmMww/CglMYRrHtVQlBOwuuYjYvRu3b3e2SrZJrW axSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253888; x=1707858688; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dGqIsAq8M3OyZBp1sy4dZz2sGDg3iZRmY3s8GmeRm7w=; b=G9AOND++sdperUGCmTrFy5u6iqO4XNUV2AOASe7MR4gsShjgQZwXEhRO/U9WcJAPCw kzxZ4faLatBmiFbsHJlKHGzHeoO2TUgPkOiSD95KO+T82LrcrL8Ywyl4RLybmxKLs17/ fLTAZb9zUBnf+OzI8H2JKO0KkQ6oCOAebIbBSeL8+rgXs5w1P+RnmElBFmiloV+3PTOd fjxASP1GjXZgloAOwKozWzoKP38shHvUhKz9YbYv9K1HMDmYU8ymbylss6FmgqI3750y Ylw+2XeNi6wK8c7sfaZT1Ui/LIO4Ku9J20csHHd3WI0G24rSW8e6OUPRXnI5UuSTDlhv XsYQ== X-Gm-Message-State: AOJu0YwPrs1Z7bDj+AJi8kHo6KJGFx4dzXZdQxUn5f6XB2P+uUqmQgbs cXSQeFwZb9RDNi1S3rzmUQwp7Jq9LfcX/d33wPVinRJSVRws7VXU X-Google-Smtp-Source: AGHT+IH+QT+iIUzRQ5L3D+fdqUUCQUSYHYayCHZOru0HudI73qg4Za4o4/+PZss825mYq5VG/3ntuA== X-Received: by 2002:a05:6a20:94cf:b0:19c:a887:e945 with SMTP id ht15-20020a056a2094cf00b0019ca887e945mr3285646pzb.45.1707253887962; Tue, 06 Feb 2024 13:11:27 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUWgSG2vQUtABNHYDEEK8r/AD4F8FwL0+d86HtZAXEtm3maMn8ROfffQrMoZVXb9Lu8mdYaRgx0Qb5Nun3d+DwZWB449TREWxZzmdwQ1P+Vb3uVgSU4PogZFhvvXhHQPYhArLaoZIqQ/NQn0EFr/DBLWS2MfsJi2e5OA8XeQJcnhfEsQaRpQUL2NyJNTppzGz5ihi6ET26WKPZx6Ztksf6rRQ== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id p12-20020a62ab0c000000b006dffb3e4d78sm2434433pff.85.2024.02.06.13.11.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:26 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id DD91236035C; Wed, 7 Feb 2024 10:11:22 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, cip-dev@lists.cip-project.org, Michael Schmitz Subject: [PATCH v3 5/8] m68k: Update ->thread.esp0 before calling syscall_trace() in ret_from_signal Date: Wed, 7 Feb 2024 10:11:01 +1300 Message-Id: <20240206211104.26421-6-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:13:06 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14837 From: Al Viro commit 50e43a57334400668952f8e551c9d87d3ed2dfef upstream. We get there when sigreturn has performed obscene acts on kernel stack; in particular, the location of pt_regs has shifted. We are about to call syscall_trace(), which might stop for tracer. If that happens, we'd better have task_pt_regs() returning correct result... Fucked-up-by: Al Viro Fixes: bd6f56a75bb2 ("m68k: Missing syscall_trace() on sigreturn") Signed-off-by: Al Viro Tested-by: Michael Schmitz Reviewed-by: Michael Schmitz Tested-by: Finn Thain Link: https://lore.kernel.org/r/YP2dMWeV1LkHiOpr@zeniv-ca.linux.org.uk Signed-off-by: Geert Uytterhoeven Cc: # 4.4 Signed-off-by: Michael Schmitz --- arch/m68k/kernel/entry.S | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S index b54ac7aba850..dbeba043b703 100644 --- a/arch/m68k/kernel/entry.S +++ b/arch/m68k/kernel/entry.S @@ -173,6 +173,8 @@ ENTRY(ret_from_signal) movel %curptr@(TASK_STACK),%a1 tstb %a1@(TINFO_FLAGS+2) jge 1f + lea %sp@(SWITCH_STACK_SIZE),%a1 + movel %a1,%curptr@(TASK_THREAD+THREAD_ESP0) jbsr syscall_trace 1: RESTORE_SWITCH_STACK addql #4,%sp From patchwork Tue Feb 6 21:11:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BCC5C4828D for ; Tue, 6 Feb 2024 22:12:37 +0000 (UTC) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mx.groups.io with SMTP id smtpd.web10.4838.1707253890596592748 for ; Tue, 06 Feb 2024 13:11:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MMCCotKw; spf=pass (domain: gmail.com, ip: 209.85.210.170, mailfrom: schmitzmic@gmail.com) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e053919b5cso1245706b3a.2 for ; Tue, 06 Feb 2024 13:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253890; x=1707858690; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=+jtx9iTIYYk4ppvGP19xVnsO3K2G5AcI22Bp2g1Lx20=; b=MMCCotKwjPmL78EOe5CSIZtHsTqT5ZQvVzxxzAhfPdeNV743vxAoEPT/OiYTNwtRmS PI9OLbYwky4TmIGtH7BNUtuSdOOIVJWzhSZhba6U1/IfBMyOIDhw4322iPVJuOI/BzMY WPphlG9Loi7pAbJPzbF2zg7JtscfCaQxKZn8aiR9Bobn8bK8DxqLShB0Dr0/5xF8MqxQ KWQJnvPrzy2LZ+4rBNp2gdBsy+Xv2yAjShBN3FhP89x91/Uo8yz3d6ZeT9TXSrmaQ0EX w8LwZoDSMk0iNoGLKbGFfO/yvvt0fq1CTZvbNOvAxgwwORA3YsarKEx2p79lwmeUgB72 L0OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253890; x=1707858690; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+jtx9iTIYYk4ppvGP19xVnsO3K2G5AcI22Bp2g1Lx20=; b=OukpVptHFfsRtbHqMJ34btGp13R0f/kg566veOM57c20leCcoqnuvs0nYZIttsHE33 oqYJ7jH0OL7tN3AO5kbCS4SaSrgPjs6AC6mjktwETzDR+daTK4hPNgSFKUgaqB91pRML mlsJ6wiOLqCEWl+u++vMKZOuWEFvL3yZ8woH8qtKzaQabVMcxWdsthIXPDvY+bN39rFu xEJ91fdNceJEnVUKo7jWKAcnXJl9tdAazZQBZK4QWy99LMdwXHrPSGJw99xZSZYDKCsu zuf171or+YlgRAhwguV22DSro/2QcdhtvZ+G+a2StpvTHxS15c/jyphxGy5Va6v4Rf7k xuxg== X-Gm-Message-State: AOJu0YyDf0koXOwTPEQBE/uaFe5CHJ/gQ5C/GXemEGEDnmYt2DGrf6K/ x9gzgmqqK78G/Pmq33b+LBRjsB1YCBJ/0EnAsgU0WNbBG1L4CCdnmItSGVgW X-Google-Smtp-Source: AGHT+IH3QGWja/WQchLDtBWv5JIcYgSc9RxCALD+HX2p30QWYeOlInRb6FYUTZHQoa+xOEYdX+Cc1A== X-Received: by 2002:a05:6a00:2348:b0:6e0:3e9b:2604 with SMTP id j8-20020a056a00234800b006e03e9b2604mr962625pfj.15.1707253889861; Tue, 06 Feb 2024 13:11:29 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVpch9cfTXSoTvkYopOEgsHTxaAzuTqlOt5rIP4FaPJSe22qmC5uF5Apxrrdjp4GmgHR0ziD+b1vXSQWf8nqJ3NlVVPIWEuIiMyaj3g9sswqisjwPWCO87fPo8LLvKbav7RhgsDIJtkTYp9kXEFJCH89FpxeXalu9ahxzN0BNkhM/3K7Bqd+ms3ggNE0xRy3mQ9DRRibkwsfcq8k+5Xm+OqQQ== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id u3-20020a62d443000000b006e025e1fa61sm2622902pfl.14.2024.02.06.13.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:28 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 9865B36031A; Wed, 7 Feb 2024 10:11:23 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, cip-dev@lists.cip-project.org, Michael Schmitz Subject: [PATCH v3 6/8] m68k: Leave stack mangling to asm wrapper of sigreturn() Date: Wed, 7 Feb 2024 10:11:02 +1300 Message-Id: <20240206211104.26421-7-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:12:36 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14833 From: Al Viro commit 0d20abde987bed05a8963c8aa4276019d54ff9e7 upstream. sigreturn has to deal with an unpleasant problem - exception stack frames have different sizes, depending upon the exception (and processor model, as well) and variable-sized part of exception frame may contain information needed for instruction restart. So when signal handler terminates and calls sigreturn to resume the execution at the place where we'd been when we caught the signal, it has to rearrange the frame at the bottom of kernel stack. Worse, it might need to open a gap in the kernel stack, shifting pt_regs towards lower addresses. Doing that from C is insane - we'd need to shift stack frames (return addresses, local variables, etc.) of C call chain, right under the nose of compiler and hope it won't fall apart horribly. What had been actually done is only slightly less insane - an inline asm in mangle_kernel_stack() moved the stuff around, then reset stack pointer and jumped to label in asm glue. However, we can avoid all that mess if the asm wrapper we have to use anyway would reserve some space on the stack between switch_stack and the C stack frame of do_{rt_,}sigreturn(). Then C part can simply memmove() pt_regs + switch_stack, memcpy() the variable part of exception frame into the opened gap - all of that without inline asm, buggering C call chain, magical jumps to asm labels, etc. Asm wrapper would need to know where the moved switch_stack has ended up - it might have been shifted into the gap we'd reserved before do_rt_sigreturn() call. That's where it needs to set the stack pointer to. So let the C part return just that and be done with that. While we are at it, the call of berr_040cleanup() we need to do when returning via 68040 bus error exception frame can be moved into C part as well. Signed-off-by: Al Viro Tested-by: Michael Schmitz Reviewed-by: Michael Schmitz Tested-by: Finn Thain Link: https://lore.kernel.org/r/YP2dTQPm1wGPWFgD@zeniv-ca.linux.org.uk Signed-off-by: Geert Uytterhoeven [MSch: Minor v4.4 backport merge conflict and compile errors fixed] Cc: # 4.4 Signed-off-by: Michael Schmitz --- arch/m68k/68000/entry.S | 3 - arch/m68k/coldfire/entry.S | 3 - arch/m68k/include/asm/traps.h | 4 ++ arch/m68k/kernel/entry.S | 49 +++++++------- arch/m68k/kernel/signal.c | 118 ++++++++++++---------------------- 5 files changed, 72 insertions(+), 105 deletions(-) diff --git a/arch/m68k/68000/entry.S b/arch/m68k/68000/entry.S index 259b3661b614..cce465e850fe 100644 --- a/arch/m68k/68000/entry.S +++ b/arch/m68k/68000/entry.S @@ -25,7 +25,6 @@ .globl system_call .globl resume .globl ret_from_exception -.globl ret_from_signal .globl sys_call_table .globl bad_interrupt .globl inthandler1 @@ -59,8 +58,6 @@ do_trace: subql #4,%sp /* dummy return address */ SAVE_SWITCH_STACK jbsr syscall_trace_leave - -ret_from_signal: RESTORE_SWITCH_STACK addql #4,%sp jra ret_from_exception diff --git a/arch/m68k/coldfire/entry.S b/arch/m68k/coldfire/entry.S index 52d312d5b4d4..1a75c1015847 100644 --- a/arch/m68k/coldfire/entry.S +++ b/arch/m68k/coldfire/entry.S @@ -51,7 +51,6 @@ sw_usp: .globl system_call .globl resume .globl ret_from_exception -.globl ret_from_signal .globl sys_call_table .globl inthandler @@ -98,8 +97,6 @@ ENTRY(system_call) subql #4,%sp /* dummy return address */ SAVE_SWITCH_STACK jbsr syscall_trace_leave - -ret_from_signal: RESTORE_SWITCH_STACK addql #4,%sp diff --git a/arch/m68k/include/asm/traps.h b/arch/m68k/include/asm/traps.h index 4aff3358fbaf..a9d5c1c870d3 100644 --- a/arch/m68k/include/asm/traps.h +++ b/arch/m68k/include/asm/traps.h @@ -267,6 +267,10 @@ struct frame { } un; }; +#ifdef CONFIG_M68040 +asmlinkage void berr_040cleanup(struct frame *fp); +#endif + #endif /* __ASSEMBLY__ */ #endif /* _M68K_TRAPS_H */ diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S index dbeba043b703..9a79733b20db 100644 --- a/arch/m68k/kernel/entry.S +++ b/arch/m68k/kernel/entry.S @@ -71,14 +71,38 @@ ENTRY(__sys_vfork) ENTRY(sys_sigreturn) SAVE_SWITCH_STACK + movel %sp,%a1 | switch_stack pointer + lea %sp@(SWITCH_STACK_SIZE),%a0 | pt_regs pointer + lea %sp@(-84),%sp | leave a gap + movel %a1,%sp@- + movel %a0,%sp@- jbsr do_sigreturn - RESTORE_SWITCH_STACK - rts + jra 1f | shared with rt_sigreturn() ENTRY(sys_rt_sigreturn) SAVE_SWITCH_STACK + movel %sp,%a1 | switch_stack pointer + lea %sp@(SWITCH_STACK_SIZE),%a0 | pt_regs pointer + lea %sp@(-84),%sp | leave a gap + movel %a1,%sp@- + movel %a0,%sp@- + | stack contents: + | [original pt_regs address] [original switch_stack address] + | [gap] [switch_stack] [pt_regs] [exception frame] jbsr do_rt_sigreturn + +1: + | stack contents now: + | [original pt_regs address] [original switch_stack address] + | [unused part of the gap] [moved switch_stack] [moved pt_regs] + | [replacement exception frame] + | return value of do_{rt_,}sigreturn() points to moved switch_stack. + + movel %d0,%sp | discard the leftover junk RESTORE_SWITCH_STACK + | stack contents now is just [syscall return address] [pt_regs] [frame] + | return pt_regs.d0 + movel %sp@(PT_OFF_D0+4),%d0 rts ENTRY(buserr) @@ -169,27 +193,6 @@ do_trace_exit: addql #4,%sp jra .Lret_from_exception -ENTRY(ret_from_signal) - movel %curptr@(TASK_STACK),%a1 - tstb %a1@(TINFO_FLAGS+2) - jge 1f - lea %sp@(SWITCH_STACK_SIZE),%a1 - movel %a1,%curptr@(TASK_THREAD+THREAD_ESP0) - jbsr syscall_trace -1: RESTORE_SWITCH_STACK - addql #4,%sp -/* on 68040 complete pending writebacks if any */ -#ifdef CONFIG_M68040 - bfextu %sp@(PT_OFF_FORMATVEC){#0,#4},%d0 - subql #7,%d0 | bus error frame ? - jbne 1f - movel %sp,%sp@- - jbsr berr_040cleanup - addql #4,%sp -1: -#endif - jra .Lret_from_exception - ENTRY(system_call) SAVE_ALL_SYS diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c index 644c2ddc8aac..8fb8ee804b3a 100644 --- a/arch/m68k/kernel/signal.c +++ b/arch/m68k/kernel/signal.c @@ -594,57 +594,35 @@ static inline int rt_save_fpu_state(struct ucontext __user *uc, struct pt_regs * static int mangle_kernel_stack(struct pt_regs *regs, int formatvec, void __user *fp) { - int fsize = frame_extra_sizes(formatvec >> 12); - if (fsize < 0) { + int extra = frame_extra_sizes(formatvec >> 12); + char buf[sizeof(((struct frame *)0)->un)]; + + if (extra < 0) { /* * user process trying to return with weird frame format */ -#ifdef DEBUG - printk("user process returning with weird frame format\n"); -#endif - return 1; + pr_debug("user process returning with weird frame format\n"); + return -1; } - if (!fsize) { - regs->format = formatvec >> 12; - regs->vector = formatvec & 0xfff; - } else { - struct switch_stack *sw = (struct switch_stack *)regs - 1; - unsigned long buf[fsize / 2]; /* yes, twice as much */ - - /* that'll make sure that expansion won't crap over data */ - if (copy_from_user(buf + fsize / 4, fp, fsize)) - return 1; - - /* point of no return */ - regs->format = formatvec >> 12; - regs->vector = formatvec & 0xfff; -#define frame_offset (sizeof(struct pt_regs)+sizeof(struct switch_stack)) - __asm__ __volatile__ ( -#ifdef CONFIG_COLDFIRE - " movel %0,%/sp\n\t" - " bra ret_from_signal\n" -#else - " movel %0,%/a0\n\t" - " subl %1,%/a0\n\t" /* make room on stack */ - " movel %/a0,%/sp\n\t" /* set stack pointer */ - /* move switch_stack and pt_regs */ - "1: movel %0@+,%/a0@+\n\t" - " dbra %2,1b\n\t" - " lea %/sp@(%c3),%/a0\n\t" /* add offset of fmt */ - " lsrl #2,%1\n\t" - " subql #1,%1\n\t" - /* copy to the gap we'd made */ - "2: movel %4@+,%/a0@+\n\t" - " dbra %1,2b\n\t" - " bral ret_from_signal\n" + if (extra && copy_from_user(buf, fp, extra)) + return -1; + regs->format = formatvec >> 12; + regs->vector = formatvec & 0xfff; + if (extra) { + void *p = (struct switch_stack *)regs - 1; + struct frame *new = (void *)regs - extra; + int size = sizeof(struct pt_regs)+sizeof(struct switch_stack); + + memmove(p - extra, p, size); + memcpy(p - extra + size, buf, extra); + current->thread.esp0 = (unsigned long)&new->ptregs; +#ifdef CONFIG_M68040 + /* on 68040 complete pending writebacks if any */ + if (new->ptregs.format == 7) // bus error frame + berr_040cleanup(new); #endif - : /* no outputs, it doesn't ever return */ - : "a" (sw), "d" (fsize), "d" (frame_offset/4-1), - "n" (frame_offset), "a" (buf + fsize/4) - : "a0"); -#undef frame_offset } - return 0; + return extra; } static inline int @@ -652,14 +630,13 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *usc, void __u { int formatvec; struct sigcontext context; - int err = 0; /* Always make any pending restarted system calls return -EINTR */ current->restart_block.fn = do_no_restart_syscall; /* get previous context */ if (copy_from_user(&context, usc, sizeof(context))) - goto badframe; + return -1; /* restore passed registers */ regs->d0 = context.sc_d0; @@ -672,15 +649,10 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *usc, void __u wrusp(context.sc_usp); formatvec = context.sc_formatvec; - err = restore_fpu_state(&context); - - if (err || mangle_kernel_stack(regs, formatvec, fp)) - goto badframe; - - return 0; + if (restore_fpu_state(&context)) + return -1; -badframe: - return 1; + return mangle_kernel_stack(regs, formatvec, fp); } static inline int @@ -697,7 +669,7 @@ rt_restore_ucontext(struct pt_regs *regs, struct switch_stack *sw, err = __get_user(temp, &uc->uc_mcontext.version); if (temp != MCONTEXT_VERSION) - goto badframe; + return -1; /* restore passed registers */ err |= __get_user(regs->d0, &gregs[0]); err |= __get_user(regs->d1, &gregs[1]); @@ -726,24 +698,17 @@ rt_restore_ucontext(struct pt_regs *regs, struct switch_stack *sw, err |= restore_altstack(&uc->uc_stack); if (err) - goto badframe; - - if (mangle_kernel_stack(regs, temp, &uc->uc_extra)) - goto badframe; + return -1; - return 0; - -badframe: - return 1; + return mangle_kernel_stack(regs, temp, &uc->uc_extra); } -asmlinkage int do_sigreturn(unsigned long __unused) +asmlinkage void *do_sigreturn(struct pt_regs *regs, struct switch_stack *sw) { - struct switch_stack *sw = (struct switch_stack *) &__unused; - struct pt_regs *regs = (struct pt_regs *) (sw + 1); unsigned long usp = rdusp(); struct sigframe __user *frame = (struct sigframe __user *)(usp - 4); sigset_t set; + int size; if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) goto badframe; @@ -755,22 +720,22 @@ asmlinkage int do_sigreturn(unsigned long __unused) set_current_blocked(&set); - if (restore_sigcontext(regs, &frame->sc, frame + 1)) + size = restore_sigcontext(regs, &frame->sc, frame + 1); + if (size < 0) goto badframe; - return regs->d0; + return (void *)sw - size; badframe: force_sig(SIGSEGV, current); - return 0; + return sw; } -asmlinkage int do_rt_sigreturn(unsigned long __unused) +asmlinkage void *do_rt_sigreturn(struct pt_regs *regs, struct switch_stack *sw) { - struct switch_stack *sw = (struct switch_stack *) &__unused; - struct pt_regs *regs = (struct pt_regs *) (sw + 1); unsigned long usp = rdusp(); struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(usp - 4); sigset_t set; + int size; if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) goto badframe; @@ -779,13 +744,14 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused) set_current_blocked(&set); - if (rt_restore_ucontext(regs, sw, &frame->uc)) + size = rt_restore_ucontext(regs, sw, &frame->uc); + if (size < 0) goto badframe; - return regs->d0; + return (void *)sw - size; badframe: force_sig(SIGSEGV, current); - return 0; + return sw; } static inline struct pt_regs *rte_regs(struct pt_regs *regs) From patchwork Tue Feb 6 21:11:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Schmitz X-Patchwork-Id: 13547861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D635FC48297 for ; Tue, 6 Feb 2024 22:13:06 +0000 (UTC) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mx.groups.io with SMTP id smtpd.web10.4837.1707253890225818726 for ; Tue, 06 Feb 2024 13:11:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20230601 header.b=epdBGFrd; spf=pass (domain: gmail.com, ip: 209.85.214.179, mailfrom: schmitzmic@gmail.com) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d72f71f222so49801525ad.1 for ; Tue, 06 Feb 2024 13:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707253889; x=1707858689; darn=lists.cip-project.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=zEkVGjcaygh1vK+ux9W8nA0sI6zRg3ppOKoN4fJJ6BY=; b=epdBGFrd04HY2yWT+r0B8d/u9yVD6KubHgHuuVBphzApifSw21AshTAwy6u0pwTtj6 L3ObSG0zlKbvloLhku5Z28S4Ijg05sYE9AXLa05ctgJK+yMch6oPIA/NVBsj3+OTfHR5 wXMI+Q/g1tsdZNZ2+YyMNJ4qiR3PknUFvuUolbnSiWyn9XXyiUVaKbGGuHuVaJSafP9d cbnaa4kbW8ZWhj59GrVhPPMxEJo8Tro6AELucyUCY4N/o1wXy5VHTsN+7VWsNBG10GvT LwuwWH1DsbHzflMjWPWCwqFRPSGQ2kO4HJPzk0Bj0AEwoFGPMAUDeGDKa5X4p68qjl/3 uPEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707253889; x=1707858689; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zEkVGjcaygh1vK+ux9W8nA0sI6zRg3ppOKoN4fJJ6BY=; b=TJCMxKYxGo7UtS6PXzyiNn+wzyJ9aHCsIVxzf8OxSwlOUZLcMa9mnPuiEO4ZGfHtyS BcSK1Wmvl4sfTTvCkTIHQwtrNCEuUVmwBZaQqWTGsrJQK78jBeg6SxaIvXPqxWwcSlk7 VO1Rt7aIAbat+yhCRYeQiUYGdGAjZWTBd1PXzw0Cpb8tF40hVFFjPuLsIT/jYr6m9Ti+ o2RJNtClQQ7kCTdVTBOR5gXs9rGCNWNZTcLLSkKrcOO/okt4drGbzjsZTKe1aHJnQbXW H7D6zoB87AhzaRaIO+Q/7Rhp2Ib+0cAbVPs0soLYOEzOAZ38cveUhtBIiBsX5kfKniSV cd8A== X-Gm-Message-State: AOJu0Yyf6O4x40iy30r10RfOrEtCauJOVmnuYa52Km8LmLSrmIuJ9FPw lJ2r78oGcwmlHSUFpsLWw40ycnu+3JFBmUoDU9yTSDRZCNCC7x2Z X-Google-Smtp-Source: AGHT+IEVQDpeGqRX22t/ElsW8RVyxONGy4C+c2+QfoHZNzG1ccDB+F+iYeDyXg7VzHseI/q1LvZGrA== X-Received: by 2002:a17:902:efd2:b0:1d8:cd7b:85fa with SMTP id ja18-20020a170902efd200b001d8cd7b85famr2318976plb.68.1707253889636; Tue, 06 Feb 2024 13:11:29 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXzLlR6223QIn6MzrC/9SXgXI21u6PCORwYuzJgobLZeAKGj3zgYW6clQvx+D3k2gsVQFSo9c5fPJU2Cqo435rbDD4pCeEJ3nvWskbpszt9OwiELhBLTdIr1tu/eS35/sh5PcjWOYhZgXzzdBzY7Pcj1kNjioeOZL23QNLJyJi9YuZdVHOpNnlAeOn6ns0UIik+D+LjDENvXdLZMbV9IVzbuQ== Received: from xplor.waratah.dyndns.org (125-236-136-221-fibre.sparkbb.co.nz. [125.236.136.221]) by smtp.gmail.com with ESMTPSA id mg3-20020a170903348300b001d91b617718sm2360050plb.98.2024.02.06.13.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 13:11:28 -0800 (PST) Received: by xplor.waratah.dyndns.org (Postfix, from userid 1000) id 59652360444; Wed, 7 Feb 2024 10:11:24 +1300 (NZDT) From: Michael Schmitz To: linux-m68k@vger.kernel.org Cc: geert@linux-m68k.org, uli@fpond.eu, fthain@linux-m68k.org, viro@zeniv.linux.org.uk, cip-dev@lists.cip-project.org, Michael Schmitz Subject: [PATCH v3 7/8] m68k: fix livelock in uaccess Date: Wed, 7 Feb 2024 10:11:03 +1300 Message-Id: <20240206211104.26421-8-schmitzmic@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240206211104.26421-1-schmitzmic@gmail.com> References: <20240206211104.26421-1-schmitzmic@gmail.com> List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 06 Feb 2024 22:13:06 -0000 X-Groupsio-URL: https://lists.cip-project.org/g/cip-dev/message/14838 From: Al Viro commit bd75497a77ccae9a5e1b0f1a3fa8283d67b21f4c upstream. m68k equivalent of 26178ec11ef3 "x86: mm: consolidate VM_FAULT_RETRY handling" If e.g. get_user() triggers a page fault and a fatal signal is caught, we might end up with handle_mm_fault() returning VM_FAULT_RETRY and not doing anything to page tables. In such case we must *not* return to the faulting insn - that would repeat the entire thing without making any progress; what we need instead is to treat that as failed (user) memory access. Tested-by: Finn Thain Tested-by: Geert Uytterhoeven Acked-by: Geert Uytterhoeven Signed-off-by: Al Viro [MSch: v4.4 backport compile errors fixes] Cc: # 4.4 Signed-off-by: Michael Schmitz --- arch/m68k/mm/fault.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/m68k/mm/fault.c b/arch/m68k/mm/fault.c index 6a94cdd0c830..f94df64c3784 100644 --- a/arch/m68k/mm/fault.c +++ b/arch/m68k/mm/fault.c @@ -139,8 +139,11 @@ good_area: fault = handle_mm_fault(mm, vma, address, flags); pr_debug("handle_mm_fault returns %d\n", fault); - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) + if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) { + if (!user_mode(regs)) + goto no_context; return 0; + } if (unlikely(fault & VM_FAULT_ERROR)) { if (fault & VM_FAULT_OOM)